mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 13:30:43 +00:00
Bump pycoolmasternet-async and add filter and error code support to CoolMastetNet (#84548)
* Add filter and error code support to CoolMastetNet * Create separate entities * Remove async_add_entities_for_platform * Fixed call to async_add_entities * Avoid using test global
This commit is contained in:
47
homeassistant/components/coolmaster/binary_sensor.py
Normal file
47
homeassistant/components/coolmaster/binary_sensor.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Binary Sensor platform for CoolMasterNet integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DATA_COORDINATOR, DATA_INFO, DOMAIN
|
||||
from .entity import CoolmasterEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the CoolMasterNet binary_sensor platform."""
|
||||
info = hass.data[DOMAIN][config_entry.entry_id][DATA_INFO]
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
|
||||
async_add_entities(
|
||||
CoolmasterCleanFilter(coordinator, unit_id, info)
|
||||
for unit_id in coordinator.data
|
||||
)
|
||||
|
||||
|
||||
class CoolmasterCleanFilter(CoolmasterEntity, BinarySensorEntity):
|
||||
"""Representation of a unit's filter state (true means need to be cleaned)."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
entity_description = BinarySensorEntityDescription(
|
||||
key="clean_filter",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
name="Clean filter",
|
||||
icon="mdi:air-filter",
|
||||
)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self._unit.clean_filter
|
||||
Reference in New Issue
Block a user