-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added binary sensor for filter cleaning. Refactored status updating. …
…Fixed an exception when unloading. Added icons for entities.
- Loading branch information
1 parent
a08fab0
commit 8f9d0fd
Showing
5 changed files
with
129 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorDeviceClass, | ||
BinarySensorEntity, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant, callback | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from .__init__ import D3netCoordinator | ||
from .climate import ACTION_DAIKIN_HA | ||
from .d3net.gateway import D3netUnit | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
) -> None: | ||
"""Initialize all the Climate Entities.""" | ||
coordinator: D3netCoordinator = entry.runtime_data | ||
entities = [] | ||
for unit in coordinator.gateway.units: | ||
entities.append(D3netSensorFilter(coordinator, unit)) | ||
async_add_entities(entities) | ||
|
||
|
||
class D3netSensorBase(CoordinatorEntity, BinarySensorEntity): | ||
"""Consolidation of sensor initialization.""" | ||
|
||
def __init__(self, coordinator: D3netCoordinator, unit: D3netUnit) -> None: | ||
"""Initialize the sensor object.""" | ||
super().__init__(coordinator, context=unit) | ||
self._unit = unit | ||
self._coordinator = coordinator | ||
self._attr_device_info: DeviceInfo = coordinator.device_info(unit) | ||
self._attr_device_name = self._attr_device_info["name"] | ||
|
||
@callback | ||
def _handle_coordinator_update(self) -> None: | ||
"""Handle updated data from the coordinator.""" | ||
self.async_write_ha_state() | ||
|
||
|
||
class D3netSensorFilter(D3netSensorBase): | ||
"""Binary Sensor object for filter cleaning alter.""" | ||
|
||
def __init__(self, coordinator: D3netCoordinator, unit: D3netUnit) -> None: | ||
"""Initialize custom properties for this sensor.""" | ||
super().__init__(coordinator, unit) | ||
self._attr_name = self._attr_device_info["name"] + " Filter" | ||
self._attr_unique_id = self._attr_name | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""State of the Clean Filter warning.""" | ||
return self._unit.status.filter_warning | ||
|
||
@property | ||
def icon(self) -> str: | ||
"""Icon for filter warning.""" | ||
return "mdi:vacuum" if self._unit.status.filter_warning else "mdi:air-filter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters