示例#1
0
    def test_repr(self):
        """ Test that repr method works. #MoreCoverage """
        self.assertEqual("<Event TestEvent[L]>", str(ha.Event("TestEvent")))

        self.assertEqual(
            "<Event TestEvent[R]: beer=nice>",
            str(ha.Event("TestEvent", {"beer": "nice"},
                         ha.EventOrigin.remote)))
    def test_home_assistant_start_stop_grouped(self):
        """ Tests if home assistant start and stop events are grouped if
            occuring in the same minute. """
        entries = list(
            logbook.humanify((
                ha.Event(EVENT_HOMEASSISTANT_STOP),
                ha.Event(EVENT_HOMEASSISTANT_START),
            )))

        self.assertEqual(1, len(entries))
        self.assert_entry(entries[0],
                          name='Home Assistant',
                          message='restarted',
                          domain=ha.DOMAIN)
示例#3
0
    def test_eq(self):
        now = dt_util.utcnow()
        data = {'some': 'attr'}
        event1, event2 = [
            ha.Event('some_type', data, time_fired=now) for _ in range(2)
        ]

        self.assertEqual(event1, event2)
    def create_state_changed_event(self, event_time_fired, entity_id, state):
        """ Create state changed event. """

        # Logbook only cares about state change events that
        # contain an old state but will not actually act on it.
        state = ha.State(entity_id, state).as_dict()

        return ha.Event(EVENT_STATE_CHANGED, {
            'entity_id': entity_id,
            'old_state': state,
            'new_state': state,
        },
                        time_fired=event_time_fired)
示例#5
0
    def test_as_dict(self):
        event_type = 'some_type'
        now = dt_util.utcnow()
        data = {'some': 'attr'}

        event = ha.Event(event_type, data, ha.EventOrigin.local, now)
        expected = {
            'event_type': event_type,
            'data': data,
            'origin': 'LOCAL',
            'time_fired': dt_util.datetime_to_str(now),
        }
        self.assertEqual(expected, event.as_dict())