Closed Skons closed 2 years ago
Looks pretty good, I do have 2 questions.
Last but not least, after publishing the code i thought that the discovery topic and data should be more ELRO Connects specific. The data is now sent to sensor.[name], and with all the above it would be better if it is something like sensor.elrok1[id]. All device specific information will show up as attributes. This will make sure a sensor is always the same device, and an alarm can be sent to that sensor even if ELRO Connects has not instantiated the device properly.
Hi, awesome. Thanks for the contribution. A few thoughts (and you might object or say you won't do it because it's too much change):
Let me know if you would be interested in writing that piece, if not we can move on with your change.
pip install pytest
), then you simply run $ pytest
in the project folder. It automatically detects the files using their names. If you look at the tests
folder and follow the tests in there it should be simple to understand. Especially the test under https://github.com/dib0/elro_connects/blob/a27a881bf4bc57034a08a8e315e8a5a04645e82e/tests/test_mqtt.py#L32 should be a good starting point (you can probably copy paste it and change the necessary parts to call the right function and change the expected output)Updated the code, with the following improvements
For the latter one, I followed your directions @hildensia but I sill needed to install ELRO Connects. Which means to test ELRO Connects, it needs to be installed after every change (am I correct?). The tests itself also generated errors on my side:
FAILED tests/test_device.py::test_calling_update_fires_updated_event - AttributeError: 'Event' object attribute 'set' is read-only
FAILED tests/test_device.py::test_setting_device_state_fires_updated_event - AttributeError: 'Event' object attribute 'set' is read-only
FAILED tests/test_device.py::test_setting_battery_level_fires_updated_event - AttributeError: 'Event' object attribute 'set' is read-only
ERROR tests/test_mqtt.py::test_handle_device_alarm_sends_alarm_message - AttributeError: 'Event' object attribute 'wait' is read-only
ERROR tests/test_mqtt.py::test_handle_device_update_sends_update_message - AttributeError: 'Event' object attribute 'wait' is read-only
you can install it in an 'editable' way. That only soft-links all the files and all changes you make are immediately available without reinstalling:
$ pip install -e .
This PR adds the ability for ELRO Connects to add the ELRO devices automatically to Home Assistant. Users can decide if they want this by only providing -a on the commandline. This makes it easy to use this tool with HA. I am also planning to create a HA addon to run ELRO Connects, it makes this tool more user friendly IMO.
To better support Home Assistant, the property State is now used to show the Alarm state instead of only using "alarm" as MQTT payload. Home Assistant is unable to know the state if the payload differs.
I hope the implementation has been done correctly.
14 is also solved within hub.py line 17. To find the issue, I added some debug logging. To have better insights in what is happening when, the logging now shows timestamps.