Пример #1
0
    def test_packet_roundtrip(self):
        props_in = {'R1': 1, 'EB': 1, 'R2': 0, 'SA': 0, 'T21': 1, 'NU': 1}

        eep = Eep(rorg=0xf6, func=0x02, type=0x02)
        packet_in = EnoceanPacketFactory.create_packet(
            eep=eep,
            destination=EnoceanTools.int_to_byte_list(0xffffffff),
            learn=False,
            **props_in
        )

        text = PickleTools.pickle_packet(packet_in)
        packet_out = PickleTools.unpickle_packet(text)

        self.assertEqual(packet_out, packet_in)
    def process_enocean_message(self, message: EnoceanMessage):
        packet = message.payload
        if packet.sender_int in self._enocean_ids_skip:
            return

        packet_type = EnoceanTools.packet_type_to_string(packet.packet_type)

        if self._dump_packet and self._logger.isEnabledFor(logging.INFO):
            self._logger.info(
                "proceed_enocean - packet: %s; sender: %s; dest: %s; RORG: %s; dump:\n%s",
                packet_type, packet.sender_hex, packet.destination_hex,
                enocean_utils.to_hex_string(packet.rorg),
                PickleTools.pickle_packet(packet))
            packet.parse()
            if packet.contains_eep:
                self._logger.debug(
                    'learn received, EEP detected, RORG: 0x%02X, FUNC: 0x%02X, TYPE: 0x%02X, Manufacturer: 0x%02X'
                    % (packet.rorg, packet.rorg_func, packet.rorg_type,
                       packet.rorg_manufacturer))  # noqa: E501

        else:
            self._logger.info(
                "proceed_enocean - packet: %s; sender: %s; dest: %s; RORG: %s",
                packet_type, packet.destination_hex,
                enocean_utils.to_hex_string(packet.rorg), packet.sender_hex)
Пример #3
0
    def test_proceed_enocean(self):
        enocean_id = 0x05555555

        device = _MockDevice()
        config = {
            CONFKEY_ENOCEAN_TARGET: enocean_id,
            CONFKEY_MQTT_CHANNEL_STATE: "channel",
            CONFKEY_ENOCEAN_SENDER: 1234,
        }
        device.set_config(config)

        time_1 = datetime.datetime.now(tz=get_localzone())

        message = EnoceanMessage(
            payload=PickleTools.unpickle(PACKET_WIN_TILTED),
            enocean_id=enocean_id)
        device.now = time_1
        device.process_enocean_message(message)

        sent_data = json.loads(device.sent_message)
        self.assertEqual(
            sent_data, {
                'device': 'mock',
                'timestamp': time_1.isoformat(),
                'since': time_1.isoformat(),
                'status': 'tilted'
            })
Пример #4
0
    def _process_actor_packet(self, packet: RadioPacket):
        if packet.rorg == 0xf6:
            return  # unknown telegramm, not used

        props = Fud61Eep.get_props_from_packet(packet)  # type: Dict
        self._logger.debug("process actor message: %s", props)
        action = Fud61Eep.get_action_from_props(props)  # type: Fud61Action

        if action.switch_state not in [SwitchStatus.ON, SwitchStatus.OFF
                                       ] or action.dim_state is None:
            if self._logger.isEnabledFor(logging.DEBUG):
                # write ascii representation to reproduce in tests
                self._logger.debug(
                    "proceed_enocean - pickled error packet:\n%s",
                    PickleTools.pickle_packet(packet))

        self._current_switch_state = action.switch_state
        if isinstance(action.dim_state,
                      int) and action.dim_state > self.MIN_DIM_STATE:
            self._last_dim_state = action.dim_state

        self._reset_offline_refresh_timer()
        self._last_status_request = self._now()

        self._publish_actor_result(action)
Пример #5
0
    def process_enocean_message(self, message: EnoceanMessage):
        packet = message.payload  # type: RadioPacket
        if packet.packet_type != PACKET.RADIO:
            self._logger.debug("skipped packet with packet_type=%s",
                               EnoceanTools.packet_type_to_string(packet.rorg))
            return
        if packet.rorg != self._eep.rorg:
            self._logger.debug("skipped packet with rorg=%s", hex(packet.rorg))
            return

        data = EnoceanTools.extract_packet_props(packet, self._eep)
        self._logger.debug("proceed_enocean - got: %s", data)

        notification = self.extract_notification(data)
        if notification.channel != self._actor_channel:
            self._logger.debug("skip channel (%s, awaiting=%s)",
                               notification.channel, self._actor_channel)
            return

        if notification.switch_state == SwitchStatus.ERROR and self._logger.isEnabledFor(
                logging.DEBUG):
            # write ascii representation to reproduce in tests
            self._logger.debug(
                "process_enocean_message - pickled error packet:\n%s",
                PickleTools.pickle_packet(packet))

        message = self._create_json_message(notification.switch_state, None)
        self._publish_mqtt(message)
 def test_extract_release(self):
     packet = PickleTools.unpickle_packet(PACKET_RELEASE)
     device = _MockDevice()
     extracted = EnoceanTools.extract_packet_props(packet, device._eep)
     action = RockerAction(press=RockerPress.RELEASE)
     expected = RockerSwitchTools.create_props(action)
     self.assertEqual(extracted, expected)
Пример #7
0
    def process_enocean_message(self, message: EnoceanMessage):
        packet = message.payload  # type: RadioPacket
        if packet.packet_type != PACKET.RADIO:
            self._logger.debug("skipped packet with packet_type=%s",
                               EnoceanTools.packet_type_to_string(packet.rorg))
            return
        if packet.rorg != self._eep.rorg:
            self._logger.debug("skipped packet with rorg=%s", hex(packet.rorg))
            return

        self._reset_offline_refresh_timer()

        data = EnoceanTools.extract_packet_props(packet, self._eep)
        self._logger.debug("proceed_enocean - got: %s", data)

        try:
            value = self.extract_handle_state(data.get("WIN"))
        except DeviceException as ex:
            self._logger.exception(ex)
            value = HandleValue.ERROR

        if value == HandleValue.ERROR and self._logger.isEnabledFor(
                logging.DEBUG):
            # write ascii representation to reproduce in tests
            self._logger.debug("proceed_enocean - pickled error packet:\n%s",
                               PickleTools.pickle_packet(packet))

        since = self._determine_and_store_since(value)

        message = self._create_message(value, since)
        self._publish_mqtt(message)
    def test_ft55(self):
        packet = PickleTools.unpickle_packet(PACKET_FT55_21L)

        # f6-02-02
        eep = Eep(rorg=0xf6, func=0x02, type=0x02)

        data = EnoceanTools.extract_props(packet, eep)
        self.assertTrue(data)
Пример #9
0
 def log_pickled_enocean_packet(cls, logger_func, packet, text):
     logger_func(
         "%s - packet: %s; sender: %s; dest: %s; RORG: %s; dump:\n%s", text,
         EnoceanTools.packet_type_to_string(packet.packet_type),
         Converter.to_hex_string(packet.sender_int),
         Converter.to_hex_string(packet.destination_int),
         Converter.to_hex_string(packet.rorg),
         PickleTools.pickle_packet(packet))
Пример #10
0
    def test_extract_1_off(self):
        packet = PickleTools.unpickle_packet(_PACKET_1_OFF)

        device = _MockDevice()
        data = EnoceanTools.extract_packet_props(packet,
                                                 _MockDevice.DEFAULT_EEP)

        notification = device.extract_notification(data)
        self.assertEqual(notification.channel, 1)
        self.assertEqual(notification.switch_state, SwitchStatus.OFF)
Пример #11
0
 def test_extract_on_33(self):
     packet = PickleTools.unpickle(PACKET_STATUS_ON_33)
     data = Fud61Eep.get_props_from_packet(packet)
     data.pop('LNRB', None)  # depends on enocean version
     self.assertEqual(data, {
         'CMD': 2,
         'EDIM': 33,
         'RMP': 0,
         'EDIMR': 0,
         'STR': 0,
         'SW': 1
     })
Пример #12
0
 def test_extract_off_0(self):
     packet = PickleTools.unpickle(PACKET_STATUS_OFF_0)
     # data = Fud61Eep.get_props_from_packet(packet, Fud61Command.DIMMING)
     data = Fud61Eep.get_props_from_packet(packet)
     data.pop('LNRB', None)  # depends on enocean version
     self.assertEqual(data, {
         'CMD': 2,
         'EDIM': 0,
         'RMP': 0,
         'EDIMR': 0,
         'STR': 0,
         'SW': 0
     })
    def test_all(self):
        dest = 0xffffffff
        sender = 0x0594f8e9

        test_items = [
            (PACKET_1, Fsb61State(type=Fsb61StateType.CLOSED, time=4.2, destination=dest, sender=sender, rssi=-74)),
            (PACKET_2, Fsb61State(type=Fsb61StateType.OPENING, destination=dest, sender=sender, rssi=-58)),
            (PACKET_3, Fsb61State(type=Fsb61StateType.OPENED, time=2.6, destination=dest, sender=sender, rssi=-64)),
            (PACKET_4, Fsb61State(type=Fsb61StateType.STOPPED, destination=dest, sender=sender, rssi=-61)),
            (PACKET_5, Fsb61State(type=Fsb61StateType.CLOSING, destination=dest, sender=sender, rssi=-57)),
        ]
        for pickeled_packet, expected_status in test_items:
            packet = PickleTools.unpickle_packet(pickeled_packet)
            status = Fsb61StateConverter.extract_packet(packet)
            self.assertEqual(status, expected_status)
    def test_extract_press(self):
        loop_data = [
            (PACKET_0_PRESS, RockerButton.ROCK0),
            (PACKET_1_PRESS, RockerButton.ROCK1),
            (PACKET_2_PRESS, RockerButton.ROCK2),
            (PACKET_3_PRESS, RockerButton.ROCK3),
        ]

        for i in range(0, 3):
            packet = PickleTools.unpickle_packet(loop_data[i][0])
            device = _MockDevice()
            extracted = EnoceanTools.extract_packet_props(packet, device._eep)
            action = RockerAction(press=RockerPress.PRESS_SHORT,
                                  button=loop_data[i][1])
            expected = RockerSwitchTools.create_props(action)
            self.assertEqual(extracted, expected)
Пример #15
0
    def test_proceed_enocean(self):
        device = self.device

        packet = PickleTools.unpickle(PACKET_STATUS_ON_33)
        message = EnoceanMessage(payload=packet,
                                 enocean_id=device._enocean_target)

        device.process_enocean_message(message)

        self.assertEqual(len(device.messages), 1)
        result = json.loads(device.messages[0])

        compare = {
            'timestamp': '2020-01-01T02:02:03+00:00',
            'status': 'on',
            'dimStatus': 33,
            'device': 'mock'
        }
        self.assertEqual(result, compare)
Пример #16
0
    def process_enocean_message(self, message: EnoceanMessage):
        packet = message.payload  # type: RadioPacket
        if packet.packet_type != PACKET.RADIO:
            self._logger.debug("skipped packet with packet_type=%s",
                               EnoceanTools.packet_type_to_string(packet.rorg))
            return

        if packet.rorg == RockerSwitchTools.DEFAULT_EEP.rorg:
            props = RockerSwitchTools.extract_props(packet)
            self._logger.debug("proceed_enocean - got=%s", props)
            action = RockerSwitchTools.extract_action(
                props)  # type: RockerAction

            if action.button == RockerButton.ROCK3:
                self._current_switch_state = SwitchStatus.ON
            elif action.button == RockerButton.ROCK2:
                self._current_switch_state = SwitchStatus.OFF
            else:
                self._current_switch_state = SwitchStatus.ERROR
        else:
            self._current_switch_state = SwitchStatus.ERROR

        if self._current_switch_state not in [
                SwitchStatus.ON, SwitchStatus.OFF
        ]:
            if self._logger.isEnabledFor(logging.DEBUG):
                self._logger.debug(
                    "proceed_enocean - pickled error packet:\n%s",
                    PickleTools.pickle_packet(packet))

        self._logger.debug("proceed_enocean - switch_state=%s",
                           self._current_switch_state)

        self._last_status_request = self._now()
        self._reset_offline_refresh_timer()

        message = self._create_json_message(self._current_switch_state)
        self._publish_mqtt(message)
    def test_open(self):
        packet = PickleTools.unpickle(PACKET_WIN_OPEN)

        comp = {'WIN': 2, 'T21': 1, 'NU': 0}
        data = EnoceanTools.extract_packet_props(packet, self.eep)
        self.assertEqual(data, comp)
 def test_ignore_unknown(self):
     packet = PickleTools.unpickle_packet(PACKET_UNKNOWN_1)
     status = Fsb61StateConverter.extract_packet(packet)
     self.assertEqual(status.type, Fsb61StateType.UNKNOWN)