Skip to content

Commit

Permalink
Rename dev_id to device_id
Browse files Browse the repository at this point in the history
  • Loading branch information
devbis committed Apr 25, 2021
1 parent f51f4d0 commit b76aa66
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lumimqtt.json.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"mqtt_host": "localhost",
"dev_id": "my-lumi-router",
"device_id": "my-lumi-router",
"mqtt_user": "",
"mqtt_password": ""
}
14 changes: 9 additions & 5 deletions lumimqtt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,26 @@ 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
'sensor_debounce_period': 60, # 1 minute
**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'),
Expand Down
4 changes: 2 additions & 2 deletions lumimqtt/lumimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit b76aa66

Please sign in to comment.