Skip to content

Commit

Permalink
Updated sensor entities.
Browse files Browse the repository at this point in the history
This adds a method to allow a manual update and properly subscribes to
entities to coordinator updates.
  • Loading branch information
boralyl committed May 28, 2020
1 parent dc7976b commit 6f8a66b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions custom_components/nintendo_wishlist/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ def name(self) -> str:
@property
def device_state_attributes(self):
return {"matches": self.matches}

async def async_update(self):
"""Update the entity.
This is only used by the generic entity update service. Normal updates
happen via the coordinator.
"""
await self.coordinator.async_request_refresh()

async def async_added_to_hass(self):
"""Subscribe entity to updates when added to hass."""
self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state)
)
16 changes: 16 additions & 0 deletions custom_components/nintendo_wishlist/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,19 @@ def state(self):
@property
def device_state_attributes(self):
return self.attrs

async def async_update(self):
"""Update the entity.
This is only used by the generic entity update service. Normal updates
happen via the coordinator.
"""
await self.coordinator.async_request_refresh()

async def async_added_to_hass(self):
"""Subscribe entity to updates when added to hass."""
self.async_on_remove(
self.coordinator.async_add_listener(
self.async_write_ha_state
)
)

0 comments on commit 6f8a66b

Please sign in to comment.