jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Parameter is None not handled #43

Closed janisHD closed 4 years ago

janisHD commented 4 years ago

Hello,

first of all, thank you for this great integration!! I have the component running for 10days without a particular issue, so far. I noticed today that several devices seemed to be not updated, during further investigation I saw that the following error occured within freeathome:

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/setup.py", line 170, in _async_setup_component hass, processed_config File "/home/homeassistant/.homeassistant/custom_components/freeathome/__init__.py", line 50, in async_setup await sysap.find_devices() File "/home/homeassistant/.homeassistant/custom_components/freeathome/pfreeathome.py", line 1008, in find_devices await self.xmpp.find_devices(self._use_room_names) File "/home/homeassistant/.homeassistant/custom_components/freeathome/pfreeathome.py", line 927, in find_devices self.add_sensor_unit(neighbor, serialnumber, roomnames, device_id) File "/home/homeassistant/.homeassistant/custom_components/freeathome/pfreeathome.py", line 755, in add_sensor_unit parameter = parameters.find('parameter') AttributeError: 'NoneType' object has no attribute 'find'

It seems that one particular device does not have parameters. In this case there is one device that was connected at some point but was removed later. The device is still kept from the SysAP with a message that the config for this device was recovered and will be updated once the device will be available again.

Would it be possible to handle this particular case officially? I overcame the issue with an additional check for None but this may not be a good solution:

# Sensor units 1/2 way if device_id == '1002' or device_id == '1000' or device_id == '100C' or \ device_id == '1019' or device_id == '1017' : if neighbor.find('parameters') is None: LOG.error('Paramters empty sensor unit: %s - %s',serialnumber, device_id) else: self.add_sensor_unit(neighbor, serialnumber, roomnames, device_id)

jheling commented 4 years ago

Sorry for the late reaction. Al lot of my free time goes into the garden.

Is it possible for you to make the get-master-message.py working? To run this source, you don't need to have a home assistant environment. Only the source tree and a python installation. This program generates a mastermessage.xml which shows all the devices in your system. I'm curious how the structure a removed device looks like.

janisHD commented 4 years ago

Hi,

issue is not of highest priority as the workaround works quite well without any degradation.

Below is a cutout of the mastermessage.xml that shows two devices. The first device is the one without any parameters, the next one is a device with usual content.

</scene></scenes></channel></descriptions><devices><device serialNumber="ABB7F592BD6E" copyId="1" isTp="true" softwareId="1556" softwareVersion="2.1366" nameId="FFF4" deviceId="100C" deviceFlavor="00" domainAddress="1011" individualAddress="0170" profile="0E00" iconId="FFFF" shortSerialNumber="PUL"><attribute name="unresponsive">true</attribute><attribute name="shadowCopy">true</attribute></device><device softwareId="1" functionId="FEFD" softwareVersion="2.5.0" nameId="02BE" protocolVersion="00FF" deviceId="FFFF" minConfigVersion="0000" deviceFlavor="00" sysAp="true" domainAddress="1011" individualAddress="01C5" profile="0810" maxAPDULength="37" compilerVersion="00000000" buildNumber="00000000" iconId="FFF8" serialNumber="ABB700000000" commissioningState="ready"><channels><channel mask="FFFFFFFF" nameId="01BF" sameLocation="true" i="ch0000" cid="ABB7FFF3"><attribute name="functionId">25</attribute><inputs><dataPoint i="idp0000"><value>0</value><address timeSlot="0" primary="true">6f0a</address></dataPoint></inputs><outputs><dataPoint i="odp0000"><value>1</value><address timeSlot="0" primary="true">e66</address></dataPoint></outputs><parameters/></channel><channel mask="FFFFFFFF" nameId="01C1" hidden="true" i="ch0001" cid="ABB7FFFB"><attribute name="functionId">26</attribute><inputs/><outputs><dataPoint i="odp0000"><value>21:58:30</value><address timeSlot="0" primary="true">3a91</address></dataPoint><dataPoint i="odp0001"><value>2020-04-12</value><address timeSlot="0" primary="true">8f18</address></dataPoint><dataPoint i="odp0002"><value>0</value><address timeSlot="0" primary="true">91f</address></dataPoint><dataPoint i="odp0003"><value>600</value><address timeSlot="0" primary="true">9f41</address></dataPoint></outputs><parameters/></channel><channel mask="FFFFFFFF" nameId="04CE" hidden="true" i="ch0002" cid="ABB7FFF1"><attribute name="functionId">86</attribute><inputs/><outputs/><parameters/></channel></channels></device><device isTp="true" domainAddress="1011" individualAddress="0177" nameId="FFF4" profile="0E00" maxAPDULength="37" compilerVersion="007A3CF9" buildNumber="00000556" iconId="FFFF" protocolVersion="0002" minConfigVersion="0001" deviceFlavor="00" interface="TP" functionId="FEFF" shortSerialNumber="PWD" softwareId="1556" softwareVersion="2.1366" deviceId="100C" serialNumber="ABB7F592BD87" commissioningState="ready"><attribute name="bitErrors">16</attribute><attribute name="busVoltage">29.865</attribute><attribute name="deviceErrors">0</attribute><attribute name="deviceReboots">13</attribute><attribute name="displayName">Flur Kinderzimmer 1.2</attribute><attribute name="floor">01</attribute><attribute name="offsetX">0.24686940966010704</attribute><attribute name="offsetY">0.417522194111242</attribute><attribute name="operationTime">1776</attribute><attribute name="parityErrors">16</attribute><attribute name="room">08</attribute><attribute name="spikeErrors">16</attribute><channels><channel mask="0000FFFF" nameId="004F" i="ch0003" cid="ABB7014F"><attribute name="displayName">Flur x7</attribute><attribute name="floor">01</attribute><attribute name="functionId">7</attribute><attribute name="offsetX">0.493548731650076</attribute><attribute name="offsetY">0.0879869226933306</attribute><attribute name="room">07</attribute><attribute name="selectedIcon">1</attribute><inputs><dataPoint i="idp0000"><value>0</value><address timeSlot="0" primary="true">f7f0</address><address timeSlot="0">edc5</address><address timeSlot="0">ac50</address><address timeSlot="0">5e0a</address><address timeSlot="0">72d3</address><address timeSlot="0">48a9</address></dataPoint></inputs><outputs><dataPoint i="odp0000"><value>0</value><address timeSlot="0" primary="true">abe2</address></dataPoint><dataPoint i="odp0001"><value>0</value><address timeSlot="0" primary="true">4cb1</address></dataPoint></outputs><parameters><parameter i="pm0000" optional="false"><value>60</value></parameter><parameter i="pm0001" optional="false"><value>1</value></parameter></parameters></channel></channels><parameters><parameter channelSelector="true" deviceChannelSelector="false" nameId="003B" parameterId="000C" accessLevel="Enduser" dependencyId="FFFF" wizardOnly="false" matchCode="FFFFFFFF" dpt="14C8" visible="true" writable="true" i="pm0000" optional="false"><valueEnum><option key="1" nameId="0065" isDefault="true" mask="00000001"/><option key="2" nameId="0121" isDefault="false" mask="00000002"/></valueEnum><value>1</value></parameter></parameters></device>

jheling commented 4 years ago

As the component is also 'unresponsive' for the sysap, i think it is better to not add such a device to homeassistant. I think i will only add devices with the commissioningState="ready".

jheling commented 4 years ago

I have included the check in the main branch