def test_get_significant_states_with_initial(opp_history): """Test that only significant states are returned. We should get back every thermostat change that includes an attribute change, but only the state updates for media player (attribute changes are not significant and not returned). """ opp = opp_history zero, four, states = record_states(opp) one = zero + timedelta(seconds=1) one_and_half = zero + timedelta(seconds=1.5) for entity_id in states: if entity_id == "media_player.test": states[entity_id] = states[entity_id][1:] for state in states[entity_id]: if state.last_changed == one: state.last_changed = one_and_half hist = get_significant_states( opp, one_and_half, four, filters=history.Filters(), include_start_time_state=True, ) assert states == hist
def test_get_significant_states_minimal_response(opp_history): """Test that only significant states are returned. When minimal responses is set only the first and last states return a complete state. We should get back every thermostat change that includes an attribute change, but only the state updates for media player (attribute changes are not significant and not returned). """ opp = opp_history zero, four, states = record_states(opp) hist = get_significant_states(opp, zero, four, filters=history.Filters(), minimal_response=True) # The second media_player.test state is reduced # down to last_changed and state when minimal_response # is set. We use JSONEncoder to make sure that are # pre-encoded last_changed is always the same as what # will happen with encoding a native state input_state = states["media_player.test"][1] orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") orig_state = input_state.state states["media_player.test"][1] = { "last_changed": orig_last_changed, "state": orig_state, } assert states == hist
def test_get_significant_states(opp_history): """Test that only significant states are returned. We should get back every thermostat change that includes an attribute change, but only the state updates for media player (attribute changes are not significant and not returned). """ opp = opp_history zero, four, states = record_states(opp) hist = get_significant_states(opp, zero, four, filters=history.Filters()) assert states == hist
def test_get_significant_states_are_ordered(self): """Test order of results from get_significant_states. When entity ids are given, the results should be returned with the data in the same order. """ zero, four, states = self.record_states() entity_ids = ["media_player.test", "media_player.test2"] hist = history.get_significant_states(self.opp, zero, four, entity_ids, filters=history.Filters()) assert list(hist.keys()) == entity_ids entity_ids = ["media_player.test2", "media_player.test"] hist = history.get_significant_states(self.opp, zero, four, entity_ids, filters=history.Filters()) assert list(hist.keys()) == entity_ids
def test_get_significant_states_entity_id(self): """Test that only significant states are returned for one entity.""" zero, four, states = self.record_states() del states["media_player.test2"] del states["thermostat.test"] del states["thermostat.test2"] del states["script.can_cancel_this_one"] hist = history.get_significant_states(self.opp, zero, four, ["media_player.test"], filters=history.Filters()) assert states == hist
def check_significant_states(opp, zero, four, states, config): """Check if significant states are retrieved.""" filters = history.Filters() exclude = config[history.DOMAIN].get(history.CONF_EXCLUDE) if exclude: filters.excluded_entities = exclude.get(history.CONF_ENTITIES, []) filters.excluded_domains = exclude.get(history.CONF_DOMAINS, []) include = config[history.DOMAIN].get(history.CONF_INCLUDE) if include: filters.included_entities = include.get(history.CONF_ENTITIES, []) filters.included_domains = include.get(history.CONF_DOMAINS, []) hist = get_significant_states(opp, zero, four, filters=filters) assert states == hist
def test_get_significant_states_multiple_entity_ids(opp_history): """Test that only significant states are returned for one entity.""" opp = opp_history zero, four, states = record_states(opp) del states["media_player.test2"] del states["media_player.test3"] del states["thermostat.test2"] del states["script.can_cancel_this_one"] hist = get_significant_states( opp, zero, four, ["media_player.test", "thermostat.test"], filters=history.Filters(), ) assert states == hist
def test_get_significant_states_without_initial(self): """Test that only significant states are returned. We should get back every thermostat change that includes an attribute change, but only the state updates for media player (attribute changes are not significant and not returned). """ zero, four, states = self.record_states() one = zero + timedelta(seconds=1) one_and_half = zero + timedelta(seconds=1.5) for entity_id in states: states[entity_id] = list( filter(lambda s: s.last_changed != one, states[entity_id])) del states["media_player.test2"] hist = history.get_significant_states( self.opp, one_and_half, four, filters=history.Filters(), include_start_time_state=False, ) assert states == hist