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 _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 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)