diff --git a/README.md b/README.md index 0ae9e62..ba01ee5 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ The configuration file is a JSON with the following content: { "mqtt_host": "localhost", "mqtt_port": 1883, - "dev_id": "my-lumi-router", "mqtt_user": "", "mqtt_password": "", - "topic_root": "lumi/{dev_id}", + "device_id": "my-lumi-router", + "topic_root": "lumi/{device_id}", "sensor_retain": false, "sensor_threshold": 50, "sensor_debounce_period": 60 @@ -32,7 +32,8 @@ The configuration file is a JSON with the following content: Every line is optional. By default, LumiMQTT will use the connection to localhost with the anonymous login. -`{dev_id}` **if not provided** will be automatically replaced by a hex number representing a MAC address. +`device_id` **if not provided** will be automatically replaced by a hex number +representing a MAC address of the first network interface. `sensor_retain` is option to enable storing last sensor value on the broker diff --git a/lumimqtt.json.sample b/lumimqtt.json.sample index e87f168..714c327 100644 --- a/lumimqtt.json.sample +++ b/lumimqtt.json.sample @@ -1,6 +1,6 @@ { "mqtt_host": "localhost", - "dev_id": "my-lumi-router", + "device_id": "my-lumi-router", "mqtt_user": "", "mqtt_password": "" } diff --git a/lumimqtt/__main__.py b/lumimqtt/__main__.py index 7406456..c5698f7 100644 --- a/lumimqtt/__main__.py +++ b/lumimqtt/__main__.py @@ -42,10 +42,10 @@ def main(): except FileNotFoundError: pass - dev_id = read_mac() + device_id = read_mac() config = { - 'dev_id': dev_id, - 'topic_root': 'lumi/{dev_id}', + 'device_id': device_id, + 'topic_root': 'lumi/{device_id}', 'mqtt_host': 'localhost', 'mqtt_port': 1883, 'sensor_threshold': 50, # 5% of illuminance sensor @@ -53,11 +53,15 @@ def main(): **config, } + topic_root = \ + config['topic_root'].\ + replace('{device_id}', device_id).\ + replace('{MAC}', device_id) # support old configs server = LumiMqtt( reconnection_interval=10, loop=loop, - dev_id=config['dev_id'], - topic_root=config['topic_root'].replace('{dev_id}', dev_id), + device_id=config['device_id'], + topic_root=topic_root, host=config['mqtt_host'], port=config['mqtt_port'], user=config.get('mqtt_user'), diff --git a/lumimqtt/lumimqtt.py b/lumimqtt/lumimqtt.py index 626832c..2877287 100644 --- a/lumimqtt/lumimqtt.py +++ b/lumimqtt/lumimqtt.py @@ -29,7 +29,7 @@ class DebounceSensor: class LumiMqtt: def __init__( self, - dev_id: str, + device_id: str, topic_root: str, host: str, port: int = None, @@ -42,7 +42,7 @@ def __init__( sensor_debounce_period: int, loop: ty.Optional[aio.AbstractEventLoop] = None, ) -> None: - self.dev_id = dev_id + self.dev_id = device_id self._topic_root = topic_root self._topic_lwt = f'{topic_root}/status' self._mqtt_host = host