Skip to content

Commit

Permalink
Don't update state for disabled devices
Browse files Browse the repository at this point in the history
fixes #28
  • Loading branch information
jason0x43 committed Mar 21, 2020
1 parent f52b4b9 commit e851b60
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions custom_components/hubitat/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
hub.set_temperature_unit(temp_unit)
for entity in hub.entities:
if entity.device_class == DEVICE_CLASS_TEMPERATURE:
entity.async_schedule_update_ha_state()
entity.update_state()

hass.states.async_set(
hub.entity_id, "connected", {CONF_TEMPERATURE_UNIT: hub.temperature_unit}
Expand Down Expand Up @@ -317,6 +317,11 @@ class HubitatEntity(HubitatBase, Entity):
# Hubitat will push device updates
should_poll = False

@property
def is_disabled(self) -> bool:
"""Indicate whether this device is currently disabled."""
return self.registry_entry and self.registry_entry.disabled_by

async def async_update(self) -> None:
"""Fetch new data for this device."""
await self._hub.refresh_device(self.device_id)
Expand All @@ -329,9 +334,14 @@ async def send_command(self, command: str, *args: Union[int, str]) -> None:

def handle_event(self, event: Event) -> None:
"""Handle a device event."""
self.async_schedule_update_ha_state()
self.update_state()
super().handle_event(event)

def update_state(self) -> None:
"""Request that Home Assistant update this device's state."""
if not self.is_disabled:
self.async_schedule_update_ha_state()


class HubitatEventEmitter(HubitatBase):
"""An event emitter related to a Hubitat device."""
Expand Down

0 comments on commit e851b60

Please sign in to comment.