def test_reconnect_notification_clears_device_error_state( plugin, indigo, zone_devices, omni1, patched_datetime): for dev in zone_devices: plugin.deviceStartComm(dev) # make the mock jomnilinkII.Connection disconnect omni1.connected.return_value = False omni1._disconnect("notConnectedEvent", Mock()) # and let the disconnect message get processed helpers.run_concurrent_thread(plugin, 1) # now the device should be in the error state for dev in zone_devices: assert dev.error_state is not None assert plugin.errorLog.called plugin.errorLog.reset_mock() # let the disconnect message get processed patched_datetime.fast_forward(minutes=2) # allow time for the thread to run by using the real sleep, # not the patched one in the plugin sleep(0.1) # let the reconnect message get processed helpers.run_concurrent_thread(plugin, 1) for dev in zone_devices: assert dev.error_state is None
def test_disconnect_sets_error_state_of_correct_unit_device( plugin, indigo, unit_devices, device_factory_fields, device_connection_props_2, device_factory_fields_2, omni2, omni_unit_types): create_unit_devices(plugin, indigo, device_factory_fields_2, omni_unit_types, device_connection_props_2) unit_devices_2 = get_unit_devices(indigo, device_factory_fields_2, omni_unit_types, device_connection_props_2) assert len(unit_devices_2) == 3 for dev in unit_devices + unit_devices_2: plugin.deviceStartComm(dev) omni2._disconnect("notConnectedEvent", Mock()) helpers.run_concurrent_thread(plugin, 1) for dev in unit_devices: assert dev.error_state is None for dev in unit_devices_2: assert dev.error_state is not None assert plugin.errorLog.called plugin.errorLog.reset_mock()
def test_other_event_notification_ignores_unknown_message( plugin, omni1, indigo, started_controller_device, trigger, trigger_non_event): omni1._notify("otherEventNotification", trigger_non_event) helpers.run_concurrent_thread(plugin, 1) assert not indigo.trigger.execute.called
def test_other_event_notification_ignores_message_for_stopped_device( plugin, omni1, indigo, started_controller_device, trigger, trigger_event): plugin.deviceStopComm(started_controller_device) omni1._notify("otherEventNotification", trigger_event) helpers.run_concurrent_thread(plugin, 1) assert not indigo.trigger.execute.called
def test_other_event_notification_updates_device_state( plugin, started_controller_device, trigger_event, omni1): omni1.reqSystemTroubles.return_value = jomni_mimic.SystemTroubles([]) assert started_controller_device.states["batteryLowTrouble"] omni1._notify("otherEventNotification", trigger_event) helpers.run_concurrent_thread(plugin, 1) assert not started_controller_device.states["batteryLowTrouble"]
def test_notification_ignores_non_zone_notifications(plugin, indigo, omni1, zone_devices): status_msg = jomni_mimic.ObjectStatus(Mock(), [jomni_mimic.ZoneStatus(1, 1, 100)]) dev = indigo.devices["Front Door"] plugin.deviceStartComm(dev) omni1._notify("objectStausNotification", status_msg) helpers.run_concurrent_thread(plugin, 1) assert dev.states["condition"] == "Secure"
def test_disconnect_notification_sets_error_state_of_correct_controller( plugin, started_controller_device, second_controller_device, omni2): plugin.deviceStartComm(second_controller_device) omni2._disconnect("notConnectedEvent", Mock()) helpers.run_concurrent_thread(plugin, 1) assert started_controller_device.error_state is None assert second_controller_device.error_state is not None assert plugin.errorLog.called plugin.errorLog.reset_mock()
def test_notification_changes_device_state(plugin, indigo, zone_devices, jomnilinkII, omni1): dev = indigo.devices["Front Door"] plugin.deviceStartComm(dev) assert dev.states["condition"] == "Secure" assert not plugin.errorLog.called status_msg = jomni_mimic.ObjectStatus(jomnilinkII.Message.OBJ_TYPE_ZONE, [jomni_mimic.ZoneStatus(1, 1, 100)]) omni1._notify("objectStausNotification", status_msg) helpers.run_concurrent_thread(plugin, 1) assert dev.states["condition"] == "Not Ready" assert not dev.states["onOffState"] assert dev.error_state is None
def test_reconnect_notification_clears_device_error_state( plugin, indigo, unit_devices, omni1, patched_datetime): for dev in unit_devices: plugin.deviceStartComm(dev) omni1.connected.return_value = False omni1._disconnect("notConnectedEvent", Mock()) helpers.run_concurrent_thread(plugin, 1) assert dev.error_state is not None assert plugin.errorLog.called plugin.errorLog.reset_mock() patched_datetime.fast_forward(minutes=2) sleep(0.1) helpers.run_concurrent_thread(plugin, 1) assert dev.error_state is None
def test_notification_changes_device_state( plugin, indigo, omni1, unit_devices, jomnilinkII_message): dev = indigo.devices["test Radio RA"] plugin.deviceStartComm(dev) assert not dev.states["onOffState"] assert dev.states["brightnessLevel"] == 0 assert not plugin.errorLog.called status_msg = jomni_mimic.ObjectStatus(jomnilinkII_message.OBJ_TYPE_UNIT, [jomni_mimic.UnitStatus(2, 1, 100)]) omni1._notify("objectStausNotification", status_msg) helpers.run_concurrent_thread(plugin, 1) assert dev.states["onOffState"] assert dev.states["brightnessLevel"] == 1 assert dev.states["timeLeftSeconds"] == 100 assert dev.error_state is None
def test_disconnect_notification_sets_error_state_of_correct_zone_device( plugin, indigo, zone_devices, device_factory_fields, omni2, zone_devices_2, device_factory_fields_2): assert len(zone_devices_2) == 3 for dev in zone_devices + zone_devices_2: plugin.deviceStartComm(dev) omni2._disconnect("notConnectedEvent", Mock()) helpers.run_concurrent_thread(plugin, 1) for dev in zone_devices: assert dev.error_state is None for dev in zone_devices_2: assert dev.error_state is not None assert plugin.errorLog.called plugin.errorLog.reset_mock()
def test_reconnect_notification_clears_device_error_state( plugin, started_controller_device, omni1, omni2, patched_datetime): # make sure controller device is running and updated omni1_system_messages_asserts(started_controller_device) helpers.run_concurrent_thread(plugin, 1) # make the mock jomnilinkII.Connection disconnect omni1.connected.return_value = False omni1._disconnect("notConnectedEvent", Mock()) # and let the disconnect message get processed helpers.run_concurrent_thread(plugin, 1) # now the device should be in the error state assert started_controller_device.error_state is not None assert plugin.errorLog.called plugin.errorLog.reset_mock() # let the disconnect message get processed patched_datetime.fast_forward(minutes=2) # allow time for the thread to run by using the real sleep, # not the patched one in the plugin sleep(0.1) # let the reconnect message get processed helpers.run_concurrent_thread(plugin, 1) assert started_controller_device.error_state is None omni2_system_messages_asserts(started_controller_device)
def test_other_event_notification_executes_trigger(plugin, omni1, indigo, trigger, trigger_event): omni1._notify("otherEventNotification", trigger_event) helpers.run_concurrent_thread(plugin, 1) assert indigo.trigger.execute.called
def test_run_concurrent_thread(plugin): helpers.run_concurrent_thread(plugin, 5)