diff --git a/elro/hub.py b/elro/hub.py
index f565d25..19d9cbb 100644
--- a/elro/hub.py
+++ b/elro/hub.py
@@ -2,8 +2,7 @@
import json
import trio
-from valideer import accepts
-import valideer
+import re
from elro.command import Command
from elro.device import create_device_from_data
@@ -19,9 +18,6 @@ class Hub:
CTRL_KEY = '0'
BIND_KEY = '0'
- @accepts(ip=valideer.Pattern(f"^(mqtt://)?({ip_address})|({hostname})$"),
- port="integer",
- device_id=valideer.Pattern("^ST_([0-9A-Fa-f]{12})$"))
def __init__(self, ip, port, device_id):
"""
Constructor
@@ -29,6 +25,13 @@ def __init__(self, ip, port, device_id):
:param port: The port of the K1 (usually 1025)
:param device_id: The device id of the K1 (starts with ST_ followed by its MAC address without colons)
"""
+ if (re.search(f"^({ip_address})|({hostname})$", ip) is None):
+ raise TypeError(f"Invalid ip ({ip})")
+ if (not isinstance(port, int)):
+ raise TypeError(f"Port should be an integer ({port})")
+ if (re.search("^ST_([0-9A-Fa-f]{12})$", device_id) is None):
+ raise TypeError(f"Invalid device id ({device_id})")
+
self.ip = ip
self.port = port
self.id = device_id
diff --git a/elro/mqtt.py b/elro/mqtt.py
index 726a741..406e4f1 100644
--- a/elro/mqtt.py
+++ b/elro/mqtt.py
@@ -1,10 +1,10 @@
import logging
import json
+import re
import trio
from distmqtt.client import open_mqttclient
from distmqtt.mqtt.constants import QOS_1
-from valideer import accepts, Pattern
from elro.validation import ip_address, hostname
@@ -13,8 +13,6 @@ class MQTTPublisher:
"""
A MQTTPublisher listens to all hub events and publishes messages to an MQTT broker accordingly
"""
- @accepts(broker_host=Pattern(f"({ip_address}|{hostname})"),
- base_topic=Pattern("^[/_\\-a-zA-Z0-9]*$"))
def __init__(self, broker_host, ha_autodiscover, base_topic=None):
"""
Constructor
@@ -23,6 +21,12 @@ def __init__(self, broker_host, ha_autodiscover, base_topic=None):
:param base_topic: The base topic to publish under, i.e., the publisher publishes messages under
/elro/
"""
+ if (re.search(f"({ip_address}|{hostname})", broker_host) is None):
+ raise TypeError(f"Invalid broker host ({broker_host})")
+
+ if (re.search("^[/_\\-a-zA-Z0-9]*$", base_topic) is None):
+ raise TypeError(f"Invalid base topic ({base_topic})")
+
self.broker_host = broker_host
if not self.broker_host.startswith("mqtt://"):
self.broker_host = f"mqtt://{self.broker_host}"
@@ -110,8 +114,7 @@ async def handle_device_discovery(self, device):
"json_attributes_topic": f"{self.topic_name(device)}",
"unique_id": f"elro_k1_device_{device.id}"
}).encode('utf8'),
- QOS_1,
- retain=True
+ QOS_1
)
async def device_message_task(self, hub):
diff --git a/elro/utils.py b/elro/utils.py
index 261f751..d3de0e6 100644
--- a/elro/utils.py
+++ b/elro/utils.py
@@ -1,8 +1,6 @@
import logging
import collections
-
-from valideer import accepts, Pattern
-
+import re
# From the ByteUtil class, needed by CRC_maker
auchCRCHi = [
@@ -81,7 +79,6 @@ def get_string_from_ascii(input):
return name
-@accepts(input=Pattern("^[_\-a-zA-Z0-9 ]*$")) # Not fully supporting a wide range of characters due to partial implementation
def get_ascii(input):
"""
This function is partially reversed engineered and translated to python
@@ -90,6 +87,9 @@ def get_ascii(input):
:param input: A string
:return: A hex string
"""
+ if (re.search("^[_\-a-zA-Z0-9 ]*$", input) is None):
+ raise TypeError("Not fully supporting a wide range of characters due to partial implementation")
+
countf = 0
try:
diff --git a/setup.cfg b/setup.cfg
index 83a0aca..becc911 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -16,7 +16,6 @@ scripts =
bin/elro
install_requires =
trio
- valideer
distmqtt
getmac
[options.extras_require]