-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inheritance #46
base: master
Are you sure you want to change the base?
Inheritance #46
Conversation
This reverts commit c4a78f8.
@fabaff This fixes the linting errors and also resoled the merge conflicts, merging the upstream master. Edit: should this be a minor release, as every device inheriting from the base class now supports the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
For the bulb example i get a trackback.
$ python examples/example-bulb.py
DEBUG:asyncio:Using selector: EpollSelector
/home/repos/python-mystrom/pymystrom/bulb.py:176: RuntimeWarning: coroutine 'MyStromDevice.__aenter__' was never awaited
super().__aenter__()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Get the details from the bulb...
Traceback (most recent call last):
File "/home/repos/python-mystrom/examples/example-bulb.py", line 65, in <module>
loop.run_until_complete(main())
File "/etc/profiles/per-user/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/repos/python-mystrom/examples/example-bulb.py", line 16, in main
await bulb.get_state()
^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_state'
I see. From what I've found I would most likely need to await the So: async def __aenter__(self) -> "MyStromBulb":
super().__aenter__() would become: async def __aenter__(self) -> "MyStromBulb":
await super().__aenter__()
return self I'll test it as soon as possible. If you have time to test it in the bulb I'll gladly update all the other files based on your feedback. |
If I understand the async context manager correctly und looking at your usage it should be good, just returning |
I've tested my pir and plug. Pir output: Settings: {'rest': True, 'panel': True, 'hap_disable': False, 'name': '', 'temp_offset': 0}
PIR settings: {'backoff_time': 180, 'led_enable': True}
Sensors: {'motion': False, 'light': 24, 'temperature': 20.62}
Temperatures: {'measured': 31.93, 'compensation': 11.31, 'compensated': 20.62, 'offset': 0}
Temperature measured: 31.93
Brightness: 24
Day?: True
Raw light data: {'visible': 24, 'infrared': 4}
Actions: {'pir': {'generic': 'get://192.168.0.11:8123/api/mystrom', 'night': '', 'twilight': '', 'day': '', 'rise': '', 'fall': ''}} Plug output: Power consumption: 13.1
Energy consumed: 22.3
Relay state: True
Temperature: 21.8
Firmware: 4.0.14
MAC address: C8F09E86BD50
Turn on the switch They also use the Little side note: Don't run the switch example if your router and wifi is plugged into it. And no I didn't just accidentally shut down my internet 👀 |
Did you have time to look into it? |
This moved the
MyStromDevice
class from the__init__.py
file into its separate file including the related functions from the__init__.py
.The imports of the
_request
function have been updated in thebulb.py
,pir.py
andswitch.py
files to reflect the changes.This also made the device classes inherit from the
MyStromDevice
base class.The
url
had to be changed to make all devices work from the base classurl
.Duplicate functions and variable assignments were removed from the inheriting classes. E.g.:
These changes were tested using the examples with the myStrom Switch and the myStrom PIR. I don't own or have bulbs, so if someone could test those, that would be great.