Esempio n. 1
0
    def testHandleEvent(self, notify_android_mock):
        d = self.monitor.persons[0].devices[0]
        d_copy = Device.from_json_string(d.to_json())
        d_copy.status = 'online'
        self.monitor.handle_event(device_status_change(d_copy.to_json()))

        self.assertTrue(notify_android_mock.called)
Esempio n. 2
0
    def handle_event(self, event):
        if event.is_device_status_change():
            device = Device.from_json_string(event.payload)
            self._log(device)

            owner = self.device_to_person_map[device.name]
            old_status = owner.status
            device_to_update = owner.get_device_by_name(device.name)
            device_to_update.status = device.status
            if old_status != owner.status:
                owner.last_status_change = datetime.now()
                # if user goes away between 22 and 7,
                # do not record event
                if owner.is_away() and \
                   is_date_between_hours(owner.last_status_change, 22, 7):
                    return

                msg = owner.name + ' is now ' + owner.status
                notify_android('presence status', msg)
                self._log(owner)