Exemplo n.º 1
0
    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.hass, zero, four, 'media_player.test',
            filters=history.Filters())
        assert states == hist
Exemplo n.º 2
0
    def test_get_significant_states(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()
        hist = history.get_significant_states(
            self.hass, zero, four, filters=history.Filters()
        )
        assert states == hist
Exemplo n.º 3
0
    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.hass,
                                              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.hass,
                                              zero,
                                              four,
                                              entity_ids,
                                              filters=history.Filters())
        assert list(hist.keys()) == entity_ids
Exemplo n.º 4
0
    def check_significant_states(self, 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 = history.get_significant_states(self.hass, zero, four, filters=filters)
        assert states == hist
Exemplo n.º 5
0
def test_get_significant_states_entity_id(hass_history):
    """Test that only significant states are returned for one entity."""
    hass = hass_history
    zero, four, states = record_states(hass)
    del states["media_player.test2"]
    del states["media_player.test3"]
    del states["thermostat.test"]
    del states["thermostat.test2"]
    del states["script.can_cancel_this_one"]

    hist = get_significant_states(
        hass, zero, four, ["media_player.test"], filters=history.Filters()
    )
    assert states == hist
Exemplo n.º 6
0
    def test_get_significant_states_multiple_entity_ids(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.test2"]
        del states["script.can_cancel_this_one"]

        hist = history.get_significant_states(
            self.hass,
            zero,
            four,
            ["media_player.test", "thermostat.test"],
            filters=history.Filters(),
        )
        assert states == hist
Exemplo n.º 7
0
    def check_significant_states(self, zero, four, states, config): \
            # pylint: disable=no-self-use
        """Check if significant states are retrieved."""
        filters = history.Filters()
        exclude = config[history.DOMAIN].get(history.CONF_EXCLUDE)
        if exclude:
            filters.excluded_entities = exclude[history.CONF_ENTITIES]
            filters.excluded_domains = exclude[history.CONF_DOMAINS]
        include = config[history.DOMAIN].get(history.CONF_INCLUDE)
        if include:
            filters.included_entities = include[history.CONF_ENTITIES]
            filters.included_domains = include[history.CONF_DOMAINS]

        hist = history.get_significant_states(zero, four, filters=filters)
        assert states == hist
Exemplo n.º 8
0
    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.hass, one_and_half, four, filters=history.Filters(),
            include_start_time_state=False)
        assert states == hist
Exemplo n.º 9
0
    def test_get_significant_states_with_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:
            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 = history.get_significant_states(
            self.hass, one_and_half, four, filters=history.Filters(),
            include_start_time_state=True)
        assert states == hist
Exemplo n.º 10
0
    def test_get_significant_states_minimal_response(self):
        """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).
        """
        zero, four, states = self.record_states()
        hist = history.get_significant_states(self.hass,
                                              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.replace(microsecond=0)),
            cls=JSONEncoder,
        ).replace('"', "")
        if orig_last_changed.endswith("+00:00"):
            orig_last_changed = f"{orig_last_changed[:-6]}{recorder.models.DB_TIMEZONE}"
        orig_state = input_state.state
        states["media_player.test"][1] = {
            "last_changed": orig_last_changed,
            "state": orig_state,
        }

        assert states == hist