Skip to content

Commit 57d6166

Browse files
committed
DeviceValue optimization. Discovery uses ProtocolHandlerMapper. Unused constants are removed.
1 parent 93210dc commit 57d6166

File tree

7 files changed

+32
-731
lines changed

7 files changed

+32
-731
lines changed

inelsmqtt/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import paho.mqtt.client as mqtt
1212

13+
from inelsmqtt.utils.core import ProtocolHandlerMapper
14+
1315
from .const import (
14-
DEVICE_TYPE_DICT,
1516
DISCOVERY_TIMEOUT_IN_SEC,
1617
FRAGMENT_DEVICE_TYPE,
1718
FRAGMENT_STATE,
@@ -410,7 +411,7 @@ def __on_discover(
410411
topic = msg.topic.split("/")[2:]
411412
topic = "/".join(topic)
412413

413-
if device_type in DEVICE_TYPE_DICT:
414+
if device_type in ProtocolHandlerMapper.DEVICE_TYPE_MAP:
414415
if action == "status":
415416
self.__discovered[topic] = msg.payload
416417
self.__last_values[msg.topic] = msg.payload
@@ -430,6 +431,8 @@ def __on_discover(
430431
self.__last_values[msg.topic] = copy.copy(msg.topic)
431432
self.__is_subscribed_list[msg.topic] = True
432433
_LOGGER.info("Device of type %s found [gw].\n", device_type)
434+
elif device_type != "gw":
435+
_LOGGER.error("No handler found for device_type: %s", device_type)
433436

434437
def __on_message(
435438
self,
@@ -450,7 +453,7 @@ def __on_message(
450453

451454
message_type = message_parts[TOPIC_FRAGMENTS[FRAGMENT_STATE]]
452455

453-
if device_type in DEVICE_TYPE_DICT or device_type == "gw":
456+
if device_type in ProtocolHandlerMapper.DEVICE_TYPE_MAP or device_type == "gw":
454457
# keep last value
455458
self.__last_values[msg.topic] = (
456459
copy.copy(self.__messages[msg.topic]) if msg.topic in self.__messages else msg.payload

0 commit comments

Comments
 (0)