home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.04k stars 31.07k forks source link

Belkin Wemo integration errors - AttributeError: 'NoneType' object has no attribute 'service' #62259

Closed LorenKeagle closed 2 years ago

LorenKeagle commented 2 years ago

The problem

My logs are filling up with the following errors from the Belkin Wemo integration:

Logger: homeassistant
Source: components/wemo/__init__.py:207
First occurred: 1:32:26 AM (30 occurrences)
Last logged: 2:52:32 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/wemo/__init__.py", line 207, in async_discover_and_schedule
    for device in await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 37, in discover_devices
    device = device_from_uuid_and_location(
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
    return Switch(location)
  File "/usr/local/lib/python3.9/site-packages/pywemo/ouimeaux_device/__init__.py", line 121, in __init__
    for svc in self._config.serviceList.service:
AttributeError: 'NoneType' object has no attribute 'service'

All of the WeMo devices in my dashboards show as 'Unavailable' due to this issue. It appears that this error was reported before and was flagged as fixed in a previous issue, but I've been updating for months now and the issue remains in my setup.

I've followed the instructions from the previous issue to run the pywemo commands directly from a python interactive shell. Here are the results of those commands:

>>> import pywemo
>>> print(pywemo.discover_devices())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 37, in discover_devices
    device = device_from_uuid_and_location(
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
    return Switch(location)
  File "/usr/local/lib/python3.9/site-packages/pywemo/ouimeaux_device/__init__.py", line 121, in __init__
    for svc in self._config.serviceList.service:
AttributeError: 'NoneType' object has no attribute 'service'
>>> print(pywemo.ssdp.scan())
[<UPNPEntry urn:Belkin:service:basicevent:1 - http://192.168.1.212:49153/setup.xml - uuid:Insight-1_0-221425K1200711>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9500/28c10c3c-e398-4bff-8d78-253fad9140da/setup.xml - uuid:Socket-1_0-28c10c3c-e398-4bff-8d78-253fad9140da>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9501/656d20b6-7972-4dc8-8f91-9525b70f4f73/setup.xml - uuid:Socket-1_0-656d20b6-7972-4dc8-8f91-9525b70f4f73>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9502/ca62d5e0-3f52-4ceb-8f72-4d70d4fcd8b1/setup.xml - uuid:Socket-1_0-ca62d5e0-3f52-4ceb-8f72-4d70d4fcd8b1>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9503/b81652e5-37ef-423f-81ea-ff689963f626/setup.xml - uuid:Socket-1_0-b81652e5-37ef-423f-81ea-ff689963f626>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9504/39921a74-bf2b-4802-8042-1f87e9dec566/setup.xml - uuid:Socket-1_0-39921a74-bf2b-4802-8042-1f87e9dec566>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9505/b54f2bb1-81ac-44d6-8b06-d39d0a33d539/setup.xml - uuid:Socket-1_0-b54f2bb1-81ac-44d6-8b06-d39d0a33d539>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9506/3868bae2-7ce4-4f6a-801b-e3b458e3dc0c/setup.xml - uuid:Socket-1_0-3868bae2-7ce4-4f6a-801b-e3b458e3dc0c>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9507/b643feca-b17e-4dec-8da4-c66065a90c5a/setup.xml - uuid:Socket-1_0-b643feca-b17e-4dec-8da4-c66065a90c5a>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9508/15af50a0-d8a6-456f-8249-bb016130df24/setup.xml - uuid:Socket-1_0-15af50a0-d8a6-456f-8249-bb016130df24>, <UPNPEntry urn:Belkin:service:basicevent:1 - http://192.168.1.207:49153/setup.xml - uuid:Insight-1_0-221424K12008BB>, <UPNPEntry urn:Belkin:device:** - http://192.168.1.110:9509/fa410272-f22e-409e-823e-fa4770a727d2/setup.xml - uuid:Socket-1_0-fa410272-f22e-409e-823e-fa4770a727d2>]
>>>

I see several non-Wemo devices showing up in this list. They appear to represent other devices on my network, such as my game consoles, etc. I'm not sure if this is the cause of the error, so please let me know if there is any more information I can gather.

What version of Home Assistant Core has the issue?

2021.12.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Belkin WeMo

Link to integration documentation on our website

https://www.home-assistant.io/integrations/wemo/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant
Source: components/wemo/__init__.py:207
First occurred: 1:32:26 AM (30 occurrences)
Last logged: 2:52:32 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/wemo/__init__.py", line 207, in async_discover_and_schedule
    for device in await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 37, in discover_devices
    device = device_from_uuid_and_location(
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
    return Switch(location)
  File "/usr/local/lib/python3.9/site-packages/pywemo/ouimeaux_device/__init__.py", line 121, in __init__
    for svc in self._config.serviceList.service:
AttributeError: 'NoneType' object has no attribute 'service'

Additional information

The integration screen indicates that I have 3 WeMo devices, but I only have entities for two of them. The 3rd device has been unplugged for at least a year. I'm not sure if that has anything to do with this issue, but it's another avenue to explore if needed.

probot-home-assistant[bot] commented 2 years ago

Hey there @esev, mind taking a look at this issue as it has been labeled with an integration (wemo) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


wemo documentation wemo source (message by IssueLinks)

esev commented 2 years ago

Thanks for adding the extra debugging. That's real helpful here!

In the print(pywemo.ssdp.scan()) output, what WeMo model are the urn:Belkin:device:** devices? Can you post a copy of the setup.xml for those (http://192.168.1.110:9500/28c10c3c-e398-4bff-8d78-253fad9140da/setup.xml)? Do you remember which version of HA was working for those before?

LorenKeagle commented 2 years ago

None of those 'devices' appear to be actual Belkin devices. I only have two Belkin WeMo Insight devices online in my home at the moment.

The other "device:**" entries all indicate an IP address of 192.168.1.110, which on my network is a NEEO remote control base station. The first one on the list appears to be associated with my PS3 console, according to the setup.xml file available from the link:

% curl http://192.168.1.110:9500/28c10c3c-e398-4bff-8d78-253fad9140da/setup.xml
<?xml version="1.0"?><root><device>
            <deviceType>urn:Fauxmo:device:controllee:1</deviceType>
            <friendlyName>PS3</friendlyName>
            <manufacturer>Belkin International Inc.</manufacturer>
            <modelName>Emulated Socket</modelName>
            <modelNumber>3.1415</modelNumber>
            <UDN>uuid:Socket-1_0-28c10c3c-e398-4bff-8d78-253fad9140da</UDN>
         </device></root>%

So, the remote control hub appears to be responding to the SSDP scan with entries for the device in my entertainment center.

LorenKeagle commented 2 years ago

I don't recall which version of HA was working last, but definitely sometime earlier this year. I went several months without updating HA, so there were a lot of changes. I haven't had time until now to figure out how to actually access the HA container to run the above commands.

FYI, I see the 'service' entries for the actual WeMo Insight devices:

% curl http://192.168.1.212:49153/setup.xml
<?xml version="1.0"?>
<root xmlns="urn:Belkin:device-1-0">
  <specVersion>
    <major>1</major>
    <minor>0</minor>
  </specVersion>
  <device>
<deviceType>urn:Belkin:device:insight:1</deviceType>
<friendlyName>Christmas Tree Lights </friendlyName>
    <manufacturer>Belkin International Inc.</manufacturer>
    <manufacturerURL>http://www.belkin.com</manufacturerURL>
    <modelDescription>Belkin Insight 1.0</modelDescription>
    <modelName>Insight</modelName>
    <modelNumber>1.0</modelNumber>
    <modelURL>http://www.belkin.com/plugin/</modelURL>
<serialNumber>********</serialNumber>
<UDN>uuid:Insight-1_0-********</UDN>
    <UPC>********</UPC>
<macAddress>*******</macAddress>
<firmwareVersion>WeMo_WW_2.00.11532.PVT-OWRT-Insight</firmwareVersion>
<iconVersion>2|49153</iconVersion>
<binaryState>1</binaryState>
    <binaryOption>1</binaryOption>
    <new_algo>1</new_algo>
    <iconList>
      <icon>
        <mimetype>jpg</mimetype>
        <width>100</width>
        <height>100</height>
        <depth>100</depth>
         <url>icon.jpg</url>
      </icon>
    </iconList>
    <serviceList>
      <service>
        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>
        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>
        <controlURL>/upnp/control/WiFiSetup1</controlURL>
        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>
        <SCPDURL>/setupservice.xml</SCPDURL>
      </service>
      <service>
        <serviceType>urn:Belkin:service:timesync:1</serviceType>
        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>
        <controlURL>/upnp/control/timesync1</controlURL>
        <eventSubURL>/upnp/event/timesync1</eventSubURL>
        <SCPDURL>/timesyncservice.xml</SCPDURL>
      </service>
      <service>
        <serviceType>urn:Belkin:service:basicevent:1</serviceType>
        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>
        <controlURL>/upnp/control/basicevent1</controlURL>
        <eventSubURL>/upnp/event/basicevent1</eventSubURL>
        <SCPDURL>/eventservice.xml</SCPDURL>
      </service>
      <service>
        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>
        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>
        <controlURL>/upnp/control/firmwareupdate1</controlURL>
        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>
        <SCPDURL>/firmwareupdate.xml</SCPDURL>
      </service>
      <service>
        <serviceType>urn:Belkin:service:rules:1</serviceType>
        <serviceId>urn:Belkin:serviceId:rules1</serviceId>
        <controlURL>/upnp/control/rules1</controlURL>
        <eventSubURL>/upnp/event/rules1</eventSubURL>
        <SCPDURL>/rulesservice.xml</SCPDURL>
      </service>

      <service>
        <serviceType>urn:Belkin:service:metainfo:1</serviceType>
        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>
        <controlURL>/upnp/control/metainfo1</controlURL>
        <eventSubURL>/upnp/event/metainfo1</eventSubURL>
        <SCPDURL>/metainfoservice.xml</SCPDURL>
      </service>

      <service>
        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>
        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>
        <controlURL>/upnp/control/remoteaccess1</controlURL>
        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>
        <SCPDURL>/remoteaccess.xml</SCPDURL>
      </service>

      <service>
        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>
        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>
        <controlURL>/upnp/control/deviceinfo1</controlURL>
        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>
        <SCPDURL>/deviceinfoservice.xml</SCPDURL>
      </service>

      <service>
        <serviceType>urn:Belkin:service:insight:1</serviceType>
        <serviceId>urn:Belkin:serviceId:insight1</serviceId>
        <controlURL>/upnp/control/insight1</controlURL>
        <eventSubURL>/upnp/event/insight1</eventSubURL>
        <SCPDURL>/insightservice.xml</SCPDURL>
      </service>

      <service>
        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>
        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>
        <controlURL>/upnp/control/smartsetup1</controlURL>
        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>
        <SCPDURL>/smartsetup.xml</SCPDURL>
      </service>

      <service>
        <serviceType>urn:Belkin:service:manufacture:1</serviceType>
        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>
        <controlURL>/upnp/control/manufacture1</controlURL>
        <eventSubURL>/upnp/event/manufacture1</eventSubURL>
        <SCPDURL>/manufacture.xml</SCPDURL>
      </service>

    </serviceList>
   <presentationURL>/pluginpres.html</presentationURL>
</device>
</root>

I suspect that the XML returned from these 'Fauxmo' devices are not being parsed as expected by pywemo. I have no idea why they are being reported as Belkin devices. It might have just been an implementation shortcut that the remote control devs took to get some integration working. In any case, I'm guessing that pywemo should probably ignore these devices.

esev commented 2 years ago

Ah! Mystery solved. Fauxmo (Faux weMo) is a WeMo emulator. It is commonly used to integrate devices with Amazon Alexa. That explains why pyWeMo is trying to parse it.

I'm working on a way to get pyWeMo to ignore these, and any other WeMo emulator that it cannot handle.

LorenKeagle commented 2 years ago

Excellent. Let me know when you've got something. Now that I can ssh directly into my HA instance, I'm happy to hack around and replace files to test things out.

esev commented 2 years ago

Excellent. Let me know when you've got something.

Will do. I'm running tests on my HA instance now. So far so good, all of my devices are still showing up.

I usually give changes a day before merging them, just to see if any of the other pyWeMo maintainers have any feedback. Once merged, I'll make a new pyWeMo release. Then you can use pip to update.

The PR is here, if you're curious: https://github.com/pywemo/pywemo/pull/302

esev commented 2 years ago

@LorenKeagle I just made a new release of pyWeMo that includes the fix. To try it out, edit your /usr/src/homeassistant/homeassistant/components/wemo/manifest.json file. Change the pywemo==0.6.7 to pywemo==0.7.0-beta.1. Then restart Home Assistant.

-  "requirements": ["pywemo==0.6.7"],
+  "requirements": ["pywemo==0.7.0-beta.1"],

Please let me know how that goes.

LorenKeagle commented 2 years ago

Appears to work for me!

I no longer see any errors on the integration page, and I can see energy readings on my dashboards again.

I do see your new errors in the system logs, however:

Logger: pywemo.discovery
Source: /usr/local/lib/python3.9/site-packages/pywemo/discovery.py:101
First occurred: 5:29:30 PM (60 occurrences)
Last logged: 5:32:32 PM

Device setup failed uuid:Socket-1_0-b54f2bb1-81ac-44d6-8b06-d39d0a33d539 http://192.168.1.110:9505/b54f2bb1-81ac-44d6-8b06-d39d0a33d539/setup.xml
Device setup failed uuid:Socket-1_0-3868bae2-7ce4-4f6a-801b-e3b458e3dc0c http://192.168.1.110:9506/3868bae2-7ce4-4f6a-801b-e3b458e3dc0c/setup.xml
Device setup failed uuid:Socket-1_0-b643feca-b17e-4dec-8da4-c66065a90c5a http://192.168.1.110:9507/b643feca-b17e-4dec-8da4-c66065a90c5a/setup.xml
Device setup failed uuid:Socket-1_0-15af50a0-d8a6-456f-8249-bb016130df24 http://192.168.1.110:9508/15af50a0-d8a6-456f-8249-bb016130df24/setup.xml
Device setup failed uuid:Socket-1_0-fa410272-f22e-409e-823e-fa4770a727d2 http://192.168.1.110:9509/fa410272-f22e-409e-823e-fa4770a727d2/setup.xml
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pywemo/discovery.py", line 71, in device_from_uuid_and_location
    return Switch(location)
  File "/usr/local/lib/python3.9/site-packages/pywemo/ouimeaux_device/__init__.py", line 167, in __init__
    self._check_required_services(self.services.values())
  File "/usr/local/lib/python3.9/site-packages/pywemo/ouimeaux_device/api/service.py", line 370, in _check_required_services
    raise MissingServiceError(
pywemo.exceptions.MissingServiceError: Missing required services/methods: basicevent(SetBinaryState, GetBinaryState)

Not sure if we're always going to see those at this point, but I would expect these to only be logged at a debug level.

esev commented 2 years ago

Good idea about making those debug logs. They'll keep going every few minutes if I don't. Thanks for the feedback and for testing!

esev commented 2 years ago

@LorenKeagle version 0.7.0 will tone-down the error logs.

I'll send a PR to get this updated in Home Assistant shortly.

Thanks again for your help on this!