def test_should_be_published(self): orig = Action() orig.channel = Channel.create(ChannelType.ITEM, 'channel') orig.state_old = State.create(StateType.DECIMAL, 2.2) orig.state_new = State.create(StateType.DECIMAL, 2.2) orig.notification_type = OhNotificationType.ITEM_CHANGE comp = copy.deepcopy(orig) out = comp.should_be_published() self.assertFalse(out) comp = copy.deepcopy(orig) comp.notification_type = OhNotificationType.ITEM_COMMAND out = comp.should_be_published() self.assertTrue(out) comp = copy.deepcopy(orig) comp.state_new = State.create(StateType.DECIMAL, 2.3) out = comp.should_be_published() self.assertTrue(out) comp = copy.deepcopy(orig) comp.channel = Channel.create(ChannelType.CRON, 'channel') out = comp.should_be_published() self.assertTrue(out)
def test_notify_action(self): expected_num = 2 self.mock_gateway.set_state( Channel.create_item(SampleRule.ITEM_DUMMY_1), State.create(StateType.DECIMAL, expected_num)) self.mock_gateway.set_state( Channel.create_item(SampleRule.ITEM_DUMMY_2), State.create(StateType.DECIMAL, None)) self.mock_gateway.set_state( Channel.create_item(SampleRule.ITEM_STRING), State.create(StateType.STRING, None)) action = Action.create_cron_action(SampleRule.CRON_NAME) self.rule.notify_action(action) self.assertEqual(2, len(self.mock_gateway.sent_actions_list)) self.assertEqual(2, len(self.mock_gateway.sent_actions_channel_dict)) value_str = self.mock_gateway.get_last_channel_data( Channel.create_item(SampleRule.ITEM_STRING)) value_num = self.mock_gateway.get_last_channel_data( Channel.create_item(SampleRule.ITEM_DUMMY_2)) self.assertTrue(value_str is not None) self.assertEqual(expected_num, value_num)
def test_get_states(self): gateway = MockOhGateway() check_channels = [] channel1 = Channel.create_item('ch1') state1 = State.create(StateType.STRING, channel1.name) gateway.set_state(channel1, state1) check_channels.append(channel1) channel2 = Channel.create_item('ch2') state2 = State.create(StateType.STRING, channel2.name) gateway.set_state(channel2, state2) check_channels.append(channel2) states = gateway.get_states() self.assertEqual(state1, states.get(channel1)) self.assertEqual(state2, states.get(channel2)) channels = gateway.get_channels() for channel in channels: check_channels.index(channel) # raises check_channels.remove(channel) self.assertEqual(0, len(check_channels))
def test_send_only_if_differ(self): rest = MockRest() gateway = MockOhGateway() gateway.set_rest(rest) channel = Channel.create_item('ch1') # test 1 state = State.create(StateType.DECIMAL, 1.11) gateway.set_state(channel, state) rest.dummy_send.clear() self.assertEqual(0, len(rest.dummy_send)) gateway.send(OhSendFlags.COMMAND | OhSendFlags.SEND_ONLY_IF_DIFFER, channel, state) gateway.send_queued() self.assertEqual(0, len(rest.dummy_send)) # test 2 rest.dummy_send.clear() self.assertEqual(0, len(rest.dummy_send)) gateway.set_state(channel, State.create(StateType.DECIMAL, 1.11)) state = State.create(StateType.DECIMAL, 1.23) gateway.send(OhSendFlags.COMMAND | OhSendFlags.SEND_ONLY_IF_DIFFER, channel, state) gateway.send_queued() self.assertEqual(1, len(rest.dummy_send)) self.assertEqual(state.value, rest.dummy_send[0].state.value)
def test_eq(self): orig = Action() orig.channel = Channel.create(ChannelType.ITEM, 'channel') orig.state_old = State.create(StateType.DECIMAL, 2.2) orig.state_new = State.create(StateType.DECIMAL, 4.4) orig.notification_type = OhNotificationType.ITEM_COMMAND comp = copy.deepcopy(orig) self.assertTrue(orig == comp) self.assertTrue(orig is not None) self.assertTrue(orig != 1) comp = copy.deepcopy(orig) orig.channel = Channel.create(ChannelType.ITEM, 'channel2') self.assertTrue(orig != comp) comp = copy.deepcopy(orig) orig.state_old = State.create(StateType.DECIMAL, 2.23) self.assertTrue(orig != comp) comp = copy.deepcopy(orig) orig.state_new = State.create(StateType.DECIMAL, 2.23) self.assertTrue(orig != comp) comp = copy.deepcopy(orig) orig.notification_type = OhNotificationType.ITEM_CHANGE self.assertTrue(orig != comp)
def check_convert_roundabout(self, state_type, state_value): state = State.convert(state_type, state_value) json_out = State.convert_to_json(state.value) if not json_out or json_out != state_value: print('check_convert_roundabout - {}\n in = {}\n out = {}'. format(state_type, state_value, json_out)) self.assertTrue(False)
def test_dispatch_action(self): dispatcher = Dispatcher() checker = DispatchCheckerRule(dispatcher) channel = Channel.create(ChannelType.ITEM, 'dummyNumber') checker.subscribe_channel_actions(channel) action_in = Action() action_in.channel = channel action_in.state_new = State.create(StateType.DECIMAL, 3) action_in.notification_type = OhNotificationType.ITEM_COMMAND self.assertTrue(len(checker.notifications) == 0) something_processed = dispatcher.dispatch() self.assertFalse(something_processed) self.assertTrue(len(checker.notifications) == 0) dispatcher.push_action(action_in) something_processed = dispatcher.dispatch() self.assertTrue(something_processed) self.assertTrue(len(checker.notifications) == 1) action_out = checker.notifications[0] action_out.listener = None # compare! compare = (action_in == action_out) self.assertTrue(compare)
def test_eq(self): orig = State() orig.type = StateType.DECIMAL orig.value = 'hgffc' comp = copy.deepcopy(orig) comp.update_last_change() self.assertTrue(orig == comp) comp = copy.deepcopy(orig) comp.type = StateType.ONOFF self.assertTrue(orig != comp) comp = copy.deepcopy(orig) comp.value = orig.value + '2' self.assertTrue(orig != comp)
def test_common(self): channel = Channel.create_item('abc') state = State.create(StateType.DECIMAL, 1.23) data = OhSendData( OhSendFlags.COMMAND | OhSendFlags.SEND_ONLY_IF_DIFFER, channel, state) data.check() # no raise self.assertTrue(data.flags & OhSendFlags.COMMAND) self.assertTrue(data.flags & OhSendFlags.SEND_ONLY_IF_DIFFER) self.assertTrue(data.is_flag(OhSendFlags.SEND_ONLY_IF_DIFFER)) self.assertTrue(data.is_send()) self.assertTrue(not data.is_update()) self.assertEqual(data.get_channel(), channel) self.assertEqual(data.get_state_value(), state.value) data = OhSendData(OhSendFlags.UPDATE | OhSendFlags.CHANNEL_AS_ITEM, channel.name, state.value) data.check() # no raise self.assertTrue(data.flags & OhSendFlags.UPDATE) self.assertTrue(data.flags & OhSendFlags.CHANNEL_AS_ITEM) self.assertTrue(data.is_flag(OhSendFlags.CHANNEL_AS_ITEM)) self.assertTrue(not data.is_send()) self.assertTrue(data.is_update()) self.assertEqual(data.get_channel(), channel) self.assertEqual(data.get_state_value(), state.value)
def check_set_value_check_type(self, state_type, value1, value2, expected_result): state = State.create(state_type, value1) result = state.set_value_check_type(copy.deepcopy(value2)) self.assertEqual(result, expected_result) if result: self.assertEqual(state.value, value2)
def test_check_fails(self): channel = Channel.create_item('abc') state = State.create(StateType.DECIMAL, 1.23) try: data = OhSendData(OhSendFlags.COMMAND | OhSendFlags.UPDATE, channel, state) data.check() # no raise self.assertTrue(False) except (TypeError, ValueError): self.assertTrue(True) try: data = OhSendData( OhSendFlags.COMMAND | OhSendFlags.CHANNEL_AS_ITEM, 123, state) data.check() # no raise self.assertTrue(False) except (TypeError, ValueError): self.assertTrue(True) try: data = OhSendData( OhSendFlags.COMMAND | OhSendFlags.CHANNEL_AS_ITEM, None, state) data.check() # no raise self.assertTrue(False) except (TypeError, ValueError): self.assertTrue(True)
def test_is_valid(self): orig = Action() orig.channel = Channel.create(ChannelType.ITEM, 'channel') orig.state_old = State.create(StateType.DECIMAL, 2.2) orig.state_new = State.create(StateType.DECIMAL, 2.2) orig.notification_type = OhNotificationType.ITEM_CHANGE cron = Action() cron.channel = Channel.create(ChannelType.CRON, 'channel') cron.state_old = None cron.state_new = None cron.notification_type = None startup = Action.create_startup_action() comp = copy.deepcopy(orig) out = comp.is_valid() self.assertTrue(out) comp = copy.deepcopy(orig) comp.state_old = None out = comp.is_valid() self.assertTrue(out) comp = copy.deepcopy(cron) out = comp.is_valid() self.assertTrue(out) comp = copy.deepcopy(orig) comp.channel.name = None out = comp.is_valid() self.assertFalse(out) comp = copy.deepcopy(orig) comp.state_new = None out = comp.is_valid() self.assertFalse(out) comp = copy.deepcopy(orig) comp.notification_type = None out = comp.is_valid() self.assertFalse(out) out = startup.is_valid() self.assertTrue(out)
def test_handle_event_default(self): # {"topic":"smarthome/items/valSockMeasPower/state","payload":"{\"type\":\"Decimal\",\"value\":\"109.01\"}","type":"ItemStateEvent"} # noinspection PyPep8 str_in = '{"topic":"smarthome/items/valSockMeasPower/state","payload":"{\\\"type\\\":\\\"Decimal\\\",\\\"value\\\":\\\"109.01\\\"}","type":"ItemStateEvent"}' # noqa oh_channel = Channel.create(ChannelType.ITEM, 'valSockMeasPower') oh_state = State.create(StateType.DECIMAL, 109.01) ev_cmp = OhEvent.create(OhNotificationType.ITEM_CHANGE, oh_channel, oh_state) self.check_handle_event(str_in, ev_cmp)
def _fill_event_from_group(event: 'OhEvent', json_data): channel_type = OhEvent.get_channel_type(event.notification_type) channel_name = OhEvent.extract_group_name(json_data.get('topic')) event.channel = Channel.create(channel_type, channel_name) # embedded structure as string! payload_text = json_data.get('payload') if payload_text: payload = json.loads(payload_text) state_type = payload.get('type') state_value = payload.get('value') event.state = State.convert(state_type, state_value)
def test__repr__(self): channel = Channel.create_item('abc') state = State.create(StateType.DECIMAL, 1.23) data = OhSendData(OhSendFlags.COMMAND, channel, state) print(str(data)) data = OhSendData(OhSendFlags.UPDATE | OhSendFlags.CHANNEL_AS_ITEM, channel.name, state.value) print(str(data)) data = OhSendData(OhSendFlags.NONE, None, None) print(str(data))
def test_does_state_value_differ(self): channel = Channel.create_item('abc') state = State.create(StateType.DECIMAL, 1.23) state_differ = State.create(StateType.DECIMAL, 1.21) data = OhSendData( OhSendFlags.COMMAND | OhSendFlags.SEND_ONLY_IF_DIFFER, channel, state) data.check() # no raise out = data.does_state_value_differ(state) self.assertEqual(False, out) out = data.does_state_value_differ(state_differ) self.assertEqual(True, out) out = data.does_state_value_differ(None) self.assertEqual(True, out) data = OhSendData( OhSendFlags.COMMAND | OhSendFlags.SEND_ONLY_IF_DIFFER, channel, state.value) data.check() # no raise out = data.does_state_value_differ(state) self.assertEqual(False, out) out = data.does_state_value_differ(state_differ) self.assertEqual(True, out) out = data.does_state_value_differ(None) self.assertEqual(True, out) channel = Channel.create_item('abc') state = None state_differ = State.create(StateType.DECIMAL, 1.21) data = OhSendData( OhSendFlags.COMMAND | OhSendFlags.SEND_ONLY_IF_DIFFER, channel, state) data.check() # no raise out = data.does_state_value_differ(state) self.assertEqual(False, out) out = data.does_state_value_differ(state_differ) self.assertEqual(True, out)
def test_notify_action_not_connected(self): self.mock_gateway.mock_is_connected = False expected_num = 2 self.mock_gateway.set_state( Channel.create_item(SampleRule.ITEM_DUMMY_1), State.create(StateType.DECIMAL, expected_num)) action = Action.create_cron_action(SampleRule.CRON_NAME) self.rule.notify_action(action) self.assertEqual(0, len(self.mock_gateway.sent_actions_list)) self.assertEqual(0, len(self.mock_gateway.sent_actions_channel_dict))
def test_convert_to_json(self): out = State.convert_to_json( datetime.datetime(2018, 12, 3, 13, 7, 45, tzinfo=tzoffset(None, 3600))) self.assertEqual(out, '2018-12-03T13:07:45.000+0100') out = State.convert_to_json(-0.123) self.assertEqual(out, '-0.123') out = State.convert_to_json(0.123) self.assertEqual(out, '0.123') out = State.convert_to_json(-123) self.assertEqual(out, '-123') out = State.convert_to_json(123) self.assertEqual(out, '123') out = State.convert_to_json(ThingStatusValue.ONLINE) self.assertEqual(out, 'ONLINE') out = State.convert_to_json(ThingStatusValue.OFFLINE) self.assertEqual(out, 'OFFLINE') out = State.convert_to_json(OnOffValue.ON) self.assertEqual(out, 'ON') out = State.convert_to_json(OnOffValue.OFF) self.assertEqual(out, 'OFF') out = State.convert_to_json(None) self.assertEqual(out, 'UNDEF')
def create_from_thing_json(json_data: dict): event = OhEvent.create_empty() event.notification_type = OhNotificationType.THING_CHANGE channel_name = json_data.get('UID') event.channel = Channel.create(ChannelType.THING, channel_name) state_value = None status_info = json_data.get('statusInfo') if status_info: state_value = status_info.get('status') event.state = State.convert(StateType.THING_STATUS.name, state_value) return event
def create_from_state_json(json_data: dict, channel_type: ChannelType): event = OhEvent.create_empty() if channel_type == ChannelType.GROUP: event.notification_type = OhNotificationType.GROUP_CHANGE else: event.notification_type = OhNotificationType.ITEM_CHANGE channel_name = json_data.get('name') event.channel = Channel.create(channel_type, channel_name) state_type = json_data.get('type') state_value = json_data.get('state') event.state = State.convert(state_type, state_value) return event
def _fill_event_from_thing(event: 'OhEvent', json_data): channel_type = OhEvent.get_channel_type(event.notification_type) channel_name = OhEvent.extract_item_name(json_data.get('topic')) event.channel = Channel.create(channel_type, channel_name) # embedded structure as string! payload_text = json_data.get('payload') if payload_text: payload = json.loads(payload_text) if isinstance(payload, list): payload_inner = payload[0] else: payload_inner = payload state_value = payload_inner.get('status') event.state = State.convert(StateType.THING_STATUS.name, state_value)
def test_fetch_thing(self): rest = OhRest(SetupTest.get_config()) time_start_loading = datetime.datetime.now() # noinspection PyPep8 json_data = { 'statusInfo': { 'status': 'ONLINE', 'statusDetail': 'NONE' }, 'editable': False, 'label': 'Homematic Bridge', 'configuration': { 'cuxdPort': 8701, 'socketMaxAlive': 900, 'installModeDuration': 60, 'reconnectInterval': 3600, 'timeout': 15, 'hmIpPort': 2010, 'discoveryTimeToLive': -1, 'wiredPort': 2000, 'gatewayType': 'ccu', 'callbackHost': '127.0.0.1', 'groupPort': 9292, 'gatewayAddress': '127.0.0.1', 'unpairOnDeletion': False, 'rfPort': 2001 }, 'properties': { 'serialNumber': 'NEQ1327832', 'firmwareVersion': '2.29.23.20171118', 'modelId': 'CCU2' }, 'UID': 'homematic:bridge:rhm', 'thingTypeUID': 'homematic:bridge', 'channels': [] } # noqa ev_out = rest._fetch_thing(time_start_loading, json_data) channel = Channel.create(ChannelType.THING, 'homematic:bridge:rhm') state = State.create(StateType.THING_STATUS, ThingStatusValue.ONLINE) ev_cmp = OhEvent.create(OhNotificationType.THING_CHANGE, channel, state) self.check_fetch_event(ev_out, ev_cmp)
def test_fetch_items(self): dispatcher = MockDispatcher() rest = MockRest() gateway = OhGateway() gateway.set_dispatcher(dispatcher) gateway.set_rest(rest) # prepare rest ev_update = OhEvent.create( OhNotificationType.ITEM_CHANGE, Channel.create(ChannelType.ITEM, 'dummySwitch'), State.create(StateType.SWITCH, OnOffValue.ON)) rest.dummy_events.append(ev_update) ev_dummy = OhEvent.create(OhNotificationType.GROUP_CHANGE, Channel.create(ChannelType.GROUP, 'gMarc'), State.create(StateType.GROUP, None)) rest.dummy_events.append(ev_dummy) ev_dummy = OhEvent.create( OhNotificationType.GROUP_CHANGE, Channel.create(ChannelType.GROUP, 'gShutter'), State.create(StateType.GROUP, '0')) rest.dummy_events.append(ev_dummy) ev_dummy = OhEvent.create( OhNotificationType.THING_CHANGE, Channel.create(ChannelType.THING, 'homematic:bridge:rhm'), State.create(StateType.THING_STATUS, ThingStatusValue.ONLINE)) rest.dummy_events.append(ev_dummy) ev_dummy = OhEvent.create( OhNotificationType.ITEM_CHANGE, Channel.create(ChannelType.ITEM, 'to_be_remove'), State.create(StateType.SWITCH, OnOffValue.ON)) gateway.push_event(ev_dummy) states_comp = gateway.get_states() self.assertEqual(1, len(states_comp)) self.assertEqual(1, len(dispatcher.queued_actions)) dispatcher.queued_actions.clear() gateway.cache_states() states_comp = gateway.get_states() self.assertEqual(len(rest.dummy_events), len(states_comp)) # find a for event_r in rest.dummy_events: state_g = states_comp.get(event_r.channel) self.assertTrue(state_g is not None) equal1 = (event_r.state == state_g) state_g2 = gateway.get_state(event_r.channel) equal2 = (event_r.state == state_g2) if not equal1 or not equal2: print( 'event_r.state == state_g:\n state_src: {}\n state_out: {}' ) self.assertEqual(state_g, event_r.state) del states_comp[event_r.channel] self.assertEqual(0, len(states_comp)) self.assertEqual(len(rest.dummy_events), len(dispatcher.queued_actions)) states_comp = dispatcher.queued_actions for event_r in rest.dummy_events: queued_action = dispatcher.queued_actions.get(event_r.channel) self.assertTrue(queued_action is not None) equal = (event_r.state == queued_action.state_new) if not equal: print( 'event_r.state == queued_action.state_new:\n state_src: {}\n state_out: {}' ) self.assertEqual(queued_action.state_new, event_r.state) del dispatcher.queued_actions[event_r.channel] self.assertEqual(0, len(states_comp)) dispatcher.queued_actions.clear() ev_update.state.value = OnOffValue.OFF ev_update.state.update_last_change() gateway.push_event(ev_update) state_g3 = gateway.get_state(ev_update.channel) self.assertEqual(ev_update.state, state_g3) self.assertEqual(1, len(dispatcher.queued_actions)) dispatcher.queued_actions.clear() gateway.push_event(ev_update) self.assertEqual(0, len(dispatcher.queued_actions)) # no change ev_update.notification_type = OhNotificationType.ITEM_COMMAND dispatcher.queued_actions.clear() gateway.push_event(ev_update) self.assertEqual(1, len(dispatcher.queued_actions))
def test_switch(self): state = State.create(StateType.SWITCH, OnOffValue.OFF) out = state.is_switched_on() self.assertEqual(False, out) out = state.is_switched_off() self.assertEqual(True, out) state = State.create(StateType.SWITCH, OnOffValue.ON) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) try: state = State.create(StateType.ONOFF, None) state.is_switched_on() self.assertFalse(True) except ValueError: pass state = State.create(StateType.HSB, HsbValue(42, 78, 0)) out = state.is_switched_on() self.assertEqual(False, out) out = state.is_switched_off() self.assertEqual(True, out) state = State.create(StateType.HSB, HsbValue(42, 78, 56)) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) state = State.create(StateType.PERCENT, 0) out = state.is_switched_on() self.assertEqual(False, out) out = state.is_switched_off() self.assertEqual(True, out) state = State.create(StateType.PERCENT, 1) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) state = State.create(StateType.PERCENT, 100) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) try: state = State.create(StateType.PERCENT, -1) state.is_switched_on() self.assertFalse(True) except ValueError: pass state = State.create(StateType.DIMMER, 0) out = state.is_switched_on() self.assertEqual(False, out) out = state.is_switched_off() self.assertEqual(True, out) state = State.create(StateType.DIMMER, 1) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) state = State.create(StateType.DIMMER, 99.9) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) state = State.create(StateType.DIMMER, 100.1) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out) try: state = State.create(StateType.DIMMER, -1) state.is_switched_on() self.assertFalse(True) except ValueError: pass try: state = State.create(StateType.DIMMER, None) state.is_switched_on() self.assertFalse(True) except ValueError: pass try: state = State.create(StateType.ONOFF, None) state.is_switched_on() self.assertFalse(True) except ValueError: pass state = State.create(StateType.ONOFF, OnOffValue.OFF) out = state.is_switched_on() self.assertEqual(False, out) out = state.is_switched_off() self.assertEqual(True, out) state = State.create(StateType.ONOFF, OnOffValue.ON) out = state.is_switched_on() self.assertEqual(True, out) out = state.is_switched_off() self.assertEqual(False, out)
def test_opening(self): state = State.create(StateType.STRING, ' closed ') out = state.is_closed() self.assertEqual(True, out) out = state.is_open() self.assertEqual(False, out) out = state.is_tilted() self.assertEqual(False, out) state = State.create(StateType.STRING, ' open ') out = state.is_closed() self.assertEqual(False, out) out = state.is_open() self.assertEqual(True, out) out = state.is_tilted() self.assertEqual(False, out) state = State.create(StateType.STRING, ' tilted ') out = state.is_closed() self.assertEqual(False, out) out = state.is_open() self.assertEqual(True, out) out = state.is_tilted() self.assertEqual(True, out) state = State.create(StateType.DECIMAL, 0) out = state.is_closed() self.assertEqual(True, out) out = state.is_open() self.assertEqual(False, out) out = state.is_tilted() self.assertEqual(False, out) state = State.create(StateType.DECIMAL, 1) out = state.is_closed() self.assertEqual(False, out) out = state.is_open() self.assertEqual(True, out) out = state.is_tilted() self.assertEqual(False, out) try: state = State.create(StateType.DECIMAL, -1) state.is_switched_on() self.assertFalse(True) except ValueError: pass try: state = State.create(StateType.DECIMAL, None) state.is_switched_on() self.assertFalse(True) except ValueError: pass try: state = State.create(StateType.STRING, None) state.is_switched_on() self.assertFalse(True) except ValueError: pass try: state = State.create(StateType.STRING, 'sfvgscf') state.is_switched_on() self.assertFalse(True) except ValueError: pass
def test_fetch_item(self): rest = OhRest(SetupTest.get_config()) time_start_loading = datetime.datetime.now() # test item # noinspection PyPep8 json_data = { 'link': 'http://127.0.0.1:8080/rest/items/dummySwitch', 'state': 'ON', 'editable': False, 'type': 'Switch', 'name': 'dummySwitch', 'category': 'settings', 'tags': [], 'groupNames': [] } # noqa ev_out = rest._fetch_item(time_start_loading, json_data) channel = Channel.create(ChannelType.ITEM, 'dummySwitch') state = State.create(StateType.SWITCH, OnOffValue.ON) ev_cmp = OhEvent.create(OhNotificationType.ITEM_CHANGE, channel, state) self.check_fetch_event(ev_out, ev_cmp) # test groups # noinspection PyPep8 json_data = { 'members': [], 'link': 'http://homeserver:8080/rest/items/gMarc', 'state': 'NULL', 'editable': False, 'type': 'Group', 'name': 'gMarc', 'label': 'Zimmer Marc', 'category': 'boy_1', 'tags': [], 'groupNames': [] } # noqa ev_out = rest._fetch_item(time_start_loading, json_data) channel = Channel.create(ChannelType.GROUP, 'gMarc') state = State.create(StateType.GROUP, None) ev_cmp = OhEvent.create(OhNotificationType.GROUP_CHANGE, channel, state) self.check_fetch_event(ev_out, ev_cmp) # noinspection PyPep8 json_data = { 'members': [], 'groupType': 'Rollershutter', 'function': { 'name': 'EQUALITY' }, 'link': 'http://homeserver:8080/rest/items/gShutter', 'state': '0', 'editable': False, 'type': 'Group', 'name': 'gShutter', 'label': 'Alle Rollläden', 'category': 'rollershutter-50', 'tags': [], 'groupNames': [] } # noqa ev_out = rest._fetch_item(time_start_loading, json_data) channel = Channel.create(ChannelType.GROUP, 'gShutter') state = State.create(StateType.GROUP, '0') ev_cmp = OhEvent.create(OhNotificationType.GROUP_CHANGE, channel, state) self.check_fetch_event(ev_out, ev_cmp)
def check_ensure_value_float(self, state_type, value_in, value_cmp): state = State.create(state_type, copy.deepcopy(value_in)) value_out = state.ensure_value_float() self.assertEqual(value_out, value_cmp)