Skip to content

Commit

Permalink
Handle restore status better #199
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Apr 16, 2024
1 parent 5a0b1c8 commit fafeeca
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/localtuya/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ async def async_added_to_hass(self):
if stored_data:
self.status_restored(stored_data)

def _update_handler(status):
def _update_handler(_status):
"""Update entity state when status was updated."""
status = _status.copy()

if status is None:
status = {}

Expand Down

2 comments on commit fafeeca

@Lurker00
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check the _status first:

2024-04-16 10:51:23.935 ERROR (SyncWorker_16) [homeassistant.util.logging] Exception in _update_handler when dispatching 'localtuya_bf027de824a9597261ef1a': (None,)
Traceback (most recent call last):
File "/config/custom_components/localtuya/entity.py", line 162, in _update_handler
status = _status.copy()
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'copy'

@xZetsubou
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that when entities shutdown it sends "None" instead of empty dict.

Please sign in to comment.