LinuxChristian / pyW215

Python interface to the d-link W215 smart plug.
MIT License
37 stars 25 forks source link

Compatibility with v1.xx #4

Closed nvella closed 8 years ago

nvella commented 8 years ago

Hi again.

Firstly I'd like to say that I've been in contact with D-Link Australia and have obtained and flashed a firmware that identifies itself as V1.24B01Beta. There doesn't seem to be a difference between this and v1.24.

After comparing pyW215 to dsp-w215-hnap (which works, surprisingly), I found a few differences in the way dsp-w215-hnap authenticated and sent state change requests. After fixing these few differences, I have managed to get pyW215 working with my v1.24 plug.

Here's a list of what I managed to get working;

Working

I'd recommend you test this patch with your 2.xx plug to ensure I haven't broken anything. I may try and work on temperature and current_consumption in the future, but that would most likely require me to decompile or reverse-engineer the phone app, as the dsp-w215-hnap implementation doesn't work there either.

LinuxChristian commented 8 years ago

Everything checks out on my plugs. A shame you could not get the temperature or consumptions to work. If would be nice if they could publish a API for this thing :)

LinuxChristian commented 8 years ago

I will bump the version in home assistant during the weekend so the legacy support is included with the next home assistant release.

nvella commented 8 years ago

Nice πŸ‘.

I did enquire with D-Link Australia regarding an IoT API in my emails, but then they just replied with the beta firmware. Not sure if it'd be worth the time asking them about the temperature and power consumption APIs.

LinuxChristian commented 8 years ago

I think they keep the platform quite closed unfortunately. They really want people to use their D-Link app/cloud solution and keep things in their infrastructure. Perhaps one day :smile:

nvella commented 8 years ago

Hey, would it be alright if I bumped the version number in HA? I understand if you're a bit busy. Edit: I also noticed that the version number in setup.py hasn't been bumped to match the new release (still on 0.2). That should be fixed before the bump in HA.

LinuxChristian commented 8 years ago

I have some state attr stuff for HA which would be nice to get into the same merge request. I will just write it up and fix the setup.py error.

nvella commented 8 years ago

Sounds good.

LinuxChristian commented 8 years ago

For some reason my switches cannot change state with the updates to HA. Could you pull my HA fork https://github.com/LinuxChristian/home-assistant and see if everything works with your switches? If it works I can send the PR and fix my issue while the changes gets merged.

LinuxChristian commented 8 years ago

The library works fine on its own and everything work with HA just not changing state. I have tried installing a fresh HA on a separate machine with no luck. Even though this is a HA issue I cannot create a PR before it has been resolved.

nvella commented 8 years ago

Just tried your fork and everything looks fine here. HA isn't throwing any errors?

My logs:

16-09-05 00:29:04 INFO (CP Server Thread-8) [homeassistant.core] Bus:Handling <Event call_service[L]: service=turn_off, domain=homeassistant, service_data=entity_id=switch.lounge_cornerlamp, service_call_id=140690595547064-5>
16-09-05 00:29:04 INFO (ThreadPool Worker 18) [homeassistant.core] Bus:Handling <Event call_service[L]: service=turn_off, domain=switch, service_data=entity_id=['switch.lounge_cornerlamp'], service_call_id=140690595547064-6>
16-09-05 00:29:07 WARNING (ThreadPool Worker 6) [pyW215.pyW215] Could not find TotalConsumption in response.
16-09-05 00:29:07 INFO (ThreadPool Worker 6) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state switch.lounge_cornerlamp=off; Current Comsumption=0 W, Temperature=0 ℃, icon=mdi:lightbulb, Total Comsumption=None W, friendly_name=Corner Lamp @ 2016-09-05T00:29:07.467172+10:00>, old_state=<state switch.lounge_cornerlamp=on; Current Comsumption=0 W, Temperature=0 ℃, icon=mdi:lightbulb, Total Comsumption=None W, friendly_name=Corner Lamp @ 2016-09-05T00:29:02.247665+10:00>, entity_id=switch.lounge_cornerlamp>
LinuxChristian commented 8 years ago

Great. Then it is perhaps only a local problem. I will send the PR to balloob and continue debugging my system πŸ˜„

LinuxChristian commented 8 years ago

PR: https://github.com/home-assistant/home-assistant/pull/3185

LinuxChristian commented 8 years ago

I must have tested on the system libraries when I merged the PR because the new protocol does not work now. Removing the <Controller>1</Controller> fixes my problems. I have made a legacy support flag to __init__.

I had to close the PR until everything was fixed. The user will now get a legacy support flag option in the configure.yaml file in HA. Just need to clean it up and test. Then I will make a new PR tomorrow.

nvella commented 8 years ago

That's fine. I didn't originally think it'd be possible to use the same protocol on both firmwares but thought it would be worth a shot. Config option for specifying legacy support should be fine.

LinuxChristian commented 8 years ago

Finally πŸ˜… https://github.com/home-assistant/home-assistant/pull/3211 https://github.com/home-assistant/home-assistant.github.io/pull/899