Exemple #1
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 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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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))
Exemple #6
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)
Exemple #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 == 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)