cgarwood / homeassistant-zwave_mqtt

Limited Pre-Release of the new OZW1.6 Z-Wave component. Currently has limited platform support. Check the README for more details.
72 stars 8 forks source link

UnboundLocalError #61

Closed avocadio closed 4 years ago

avocadio commented 4 years ago

I'm testing MQTT Zwave, and reporting my first bug :)

https://github.com/cgarwood/homeassistant-zwave_mqtt/blob/08fc96f3ab7fff37f77057f7a8da8d4c8c9e448c/custom_components/zwave_mqtt/sensor.py#L33

Exception in async_add_sensor when dispatching 'zwave_new_sensor': (<custom_components.zwave_mqtt.entity.ZWaveDeviceEntityValues object at 0xae7575d0>,)
Traceback (most recent call last):
File "/config/custom_components/zwave_mqtt/sensor.py", line 33, in async_add_sensor async_add_entities([sensor])
UnboundLocalError: local variable 'sensor' referenced before assignment

balloob commented 4 years ago

Thanks! Opened a fix in #62!

avocadio commented 4 years ago

Thanks! I know have an expected warning: Sensor not implemented for value <custom_components.zwave_mqtt.entity.ZWaveDeviceEntityValues object at 0xae7d62b0>

balloob commented 4 years ago

oh, that log statement was pretty useless 🤔 Updated the PR.

avocadio commented 4 years ago

This was still referring to memory addresses so decided to get my hands dirty :)

This is a modest 1st PR

The output is as follow: Sensor not implemented for value <custom_components.zwave_mqtt.entity.ZWaveDeviceEntityValues object at 0xae6b7dd0>: {'_hass': <homeassistant.core.HomeAssistant object at 0xb515cff0>, '_schema': {'component': 'sensor', 'values': {'power': {'schemas': [{'command_class': [49], 'index': [4]}, {'command_class': [50], 'index': [2]}], 'optional': True, 'instance': [1]}, 'primary': {'command_class': [49, 50, 113, 156, 135, 128], 'genre': 'User', 'instance': [1]}}, 'node_id': [22]}, '_values': {'power': None, 'primary': <openzwavemqtt.models.value.OZWValue object at 0xae6b7ef0>}, '_entity': None, '_entity_created': True, '_options': <openzwavemqtt.options.OZWOptions object at 0xb14805d0>, '_node': <openzwavemqtt.models.node.OZWNode object at 0xae68f470>}

balloob commented 4 years ago

Instead of dumping all the instance variables of an object, let's add __repr__ functions to all the models in https://github.com/cgarwood/python-openzwave-mqtt

balloob commented 4 years ago

Formatted output

{'_entity': None,
 '_entity_created': True,
 '_schema': {'component': 'sensor',
             'node_id': [22],
             'values': {'power': {'instance': [1],
                                  'optional': True,
                                  'schemas': [{'command_class': [49],
                                               'index': [4]},
                                              {'command_class': [50],
                                               'index': [2]}]},
                        'primary': {'command_class': [49,
                                                      50,
                                                      113,
                                                      156,
                                                      135,
                                                      128],
                                    'genre': 'User',
                                    'instance': [1]}}},
 '_values': {'power': None}}