Skip to content

Commit

Permalink
Fix: AttributeError: 'NoneType' object has no attribute 'device_class'
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Apr 27, 2023
1 parent 2bfe074 commit e7b8e40
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions custom_components/tapo_control/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def __init__(self, uid, events, name, camData):
self._attr_entity_category = event.entity_category
self._attr_entity_registry_enabled_default = event.entity_enabled
self._attr_is_on = event.value
self._attr_device_class = event.device_class
self._attr_enabled = event.entity_enabled
BinarySensorEntity.__init__(self)
LOGGER.debug("TapoMotionSensor - init - end")

Expand All @@ -172,15 +174,19 @@ def name(self) -> str:

@property
def device_class(self) -> Optional[str]:
return self.events.get_uid(self.uid).device_class
if (event := self.events.get_uid(self._attr_unique_id)) is not None:
return event.device_class
return self._attr_device_class

@property
def unique_id(self) -> str:
return self.uid

@property
def entity_registry_enabled_default(self) -> bool:
return self.events.get_uid(self.uid).entity_enabled
if (event := self.events.get_uid(self._attr_unique_id)) is not None:
return event.entity_enabled
return self._attr_enabled

@property
def should_poll(self) -> bool:
Expand Down

0 comments on commit e7b8e40

Please sign in to comment.