D-link W215 Switch firmware update stopped them from working with HA

Hi,

Okay, so are not using the legacy protocol. The recent changes in the PyW215 was only affecting the legacy protocol. It does not change anything for the newer protocol…
And it seems that the issue arises as soon as the first connection to the plug. My suspicion is that it more comes from a change in another library.
One way to confirm it is not the pyW215, is if you can place in the config folder of HASS or HASSIO the following:
Create folders /custom_components/switch/
Add the file dlink.py from there: https://raw.githubusercontent.com/home-assistant/home-assistant/0.52.1/homeassistant/components/switch/dlink.py
Restart HA. It basically forces HA to use the dlink version from HA 0.52.1

Can you please test on an updated version of HA ?
(or else, you could do contrary and try the new version of the dlink on an old version of HA, it would be this dlink file then:
https://raw.githubusercontent.com/home-assistant/home-assistant/0.56.2/homeassistant/components/switch/dlink.py)

Now, to help correctly fix the issue going forward, we would need to understand what exactly go wrong.
If you are able to help us, in the /custom_components/switch/ folder replace the dlink.py file available here: https://pastebin.com/TmentLhN
Also make sure you have this in the configuration.yaml:

logger:
  default: error
  logs:
    custom_components.switch: debug

Restart HA (possibly test under 0.52 and 0.53+)
Paste here the output

Let me know if you need clarifications

Thank you so much for your time to respond and the detailed instructions. I tried all of the options you listed above:

  1. HA 56.2 with current dlink.py
  2. HA 56.2 with dlink.py from 52.1
  3. HA 52.1 with current dlink.py
  4. HA 52.1 with dlink.py from 52.1
  5. HASSIO 56.2
    The results for all are identical and some switches show up, other switches don’t show up. To be clear, the same switches show up or don’t show up across all three combinations. The error is the same every time - copied the error below. I’m also following another thread which seems like a similar (the same) issue: https://community.home-assistant.io/t/d-link-motion-sensor-dch-s150/9850/17

Here is the error
2017-11-02 17:21:51 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform dlink
Traceback (most recent call last):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 170, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File “/usr/lib/python3.4/asyncio/tasks.py”, line 372, in wait_for
return fut.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 450, in setup_platform
use_legacy_protocol))
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 77, in init
self.model_name = self.SOAPAction(Action=“GetDeviceSettings”, responseElement=“ModelName”, params = “”)
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 148, in SOAPAction
self.authenticated = self.auth()
File “/home/hass/.homeassistant/custom_components/switch/dlink.py”, line 325, in auth
response = urlopen(Request(self.url, payload, headers))
File “/usr/lib/python3.4/urllib/request.py”, line 153, in urlopen
return opener.open(url, data, timeout)
File “/usr/lib/python3.4/urllib/request.py”, line 461, in open
response = meth(req, response)
File “/usr/lib/python3.4/urllib/request.py”, line 571, in http_response
‘http’, request, response, code, msg, hdrs)
File “/usr/lib/python3.4/urllib/request.py”, line 499, in error
return self._call_chain(*args)
File “/usr/lib/python3.4/urllib/request.py”, line 433, in _call_chain
result = func(*args)
File “/usr/lib/python3.4/urllib/request.py”, line 579, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

Sorry for the late reply, but I noticed that the supplied module (from HA 0.52.1) does not appear to include a PIN code (password).

Could that explain why some plugs respond, and others don’t? IE: they are expecting different passwords?

My dlinks (also AU/NZ) are on version 1.26 and are not working. My log reports:
Failed to connect to D-Link switch

14:47:37 – dlink (WARNING) - message first occurred at 14:25:36 and shows up 10 times

Waiting 4.001320883333333 s to retry

14:47:37 – dlink (WARNING) - message first occurred at 14:29:37 and shows up 14 times

Error doing job: Task exception was never retrieved

14:25:42 – components/stream/worker.py (ERROR)

Failed to receive initial authentication from smartplug.

14:25:36 – /usr/local/lib/python3.8/site-packages/pyW215/pyW215.py (WARNING) - message first occurred at 14:25:36 and shows up 2 times

There is no dlink.py anywher in my configurtaion, yet these switches workwed till recently. I looked in /usr/share/hassio and in the python-3.8 folders and then ran 'find; across my entire Ubuntu configuration. Is dlink.py still used. The log above refers to pyW215.py