Skip to content

Commit

Permalink
Merge pull request #21 from vaproloff/dev
Browse files Browse the repository at this point in the history
Attempted to fix filter_replacement binary_sensor state
  • Loading branch information
vaproloff authored Dec 18, 2024
2 parents 5d76926 + 46c98bc commit f82907d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions custom_components/tion/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def async_setup_entry(
client: TionClient = hass.data[DOMAIN][entry.entry_id]

entities = [
TionFilterNeedReplacementBinarySensor(client, device)
TionFilterNeedReplacementBinarySensor(hass, client, device)
for device in await client.get_devices()
if device.type in [TionDeviceType.BREEZER_3S, TionDeviceType.BREEZER_4S]
]
Expand All @@ -39,10 +39,12 @@ class TionBinarySensor(BinarySensorEntity, abc.ABC):

def __init__(
self,
hass: HomeAssistant | None,
client: TionClient,
device: TionZoneDevice,
) -> None:
"""Initialize binary sensor device."""
self.hass = hass
self._api = client
self._device = device

Expand Down Expand Up @@ -92,22 +94,26 @@ class TionFilterNeedReplacementBinarySensor(TionBinarySensor):

def __init__(
self,
hass: HomeAssistant | None,
client: TionClient,
device: TionZoneDevice,
) -> None:
"""Initialize sensor device."""
super().__init__(client, device)
super().__init__(hass, client, device)

self._attr_device_class = BinarySensorDeviceClass.PROBLEM

if new_state := bool(self._device.data.filter_need_replace):
_LOGGER.debug("hass: %s", self.hass)

state = bool(self._device.data.filter_need_replace)
if state:
persistent_notification.async_create(
self.hass,
f"{self._device.name}' needs filters replacement.",
title="Tion",
notification_id="filter_need_replacement",
)
self._attr_is_on = new_state
self._attr_is_on = state

@property
def unique_id(self):
Expand All @@ -122,10 +128,9 @@ def name(self):
async def _load(self, force=False):
"""Update device data from API."""
if await super()._load(force=force):
if (
new_state := bool(self._device.data.filter_need_replace)
and not self._attr_is_on
):
new_state = bool(self._device.data.filter_need_replace)

if new_state and not self._attr_is_on:
persistent_notification.async_create(
self.hass,
f"{self._device.name}' needs filters replacement.",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/vaproloff/tion_home_assistant/issues",
"requirements": [],
"version": "2024.11.3"
"version": "2024.12.0"
}

0 comments on commit f82907d

Please sign in to comment.