-
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.
add child_lock, online, brightness, and light.
- Loading branch information
kai.tseng
committed
May 8, 2023
1 parent
b43a07b
commit 5e7b5dc
Showing
7 changed files
with
215 additions
and
36 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,82 @@ | ||
from __future__ import annotations | ||
|
||
from .const import DOMAIN | ||
from .device import BlueairDataUpdateCoordinator | ||
from .entity import BlueairEntity | ||
|
||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorDeviceClass, | ||
BinarySensorEntity | ||
) | ||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Set up the Blueair sensors from config entry.""" | ||
devices: list[BlueairDataUpdateCoordinator] = hass.data[DOMAIN][ | ||
config_entry.entry_id | ||
]["devices"] | ||
entities = [] | ||
for device in devices: | ||
# Don't add sensors to classic models | ||
if ( | ||
device.model.startswith("classic") and not device.model.endswith("i") | ||
) or device.model == "foobot": | ||
pass | ||
else: | ||
entities.extend( | ||
[ | ||
BlueairFilterExpiredSensor(f"{device.device_name}_filter_expired", device), | ||
BlueairChildLockSensor(f"{device.device_name}_child_lock", device), | ||
BlueairOnlineSensor(f"{device.device_name}_online", device), | ||
] | ||
) | ||
async_add_entities(entities) | ||
|
||
|
||
class BlueairFilterExpiredSensor(BlueairEntity, BinarySensorEntity): | ||
"""Monitors the status of the Filter""" | ||
|
||
def __init__(self, name, device): | ||
"""Initialize the filter_status sensor.""" | ||
super().__init__("filter_expired", name, device) | ||
self._state: bool = None | ||
self._attr_icon = "mdi:air-filter" | ||
self._attr_device_class = BinarySensorDeviceClass.PROBLEM | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
"""Return the current filter_status.""" | ||
return self._device.filter_expired | ||
|
||
|
||
class BlueairChildLockSensor(BlueairEntity, BinarySensorEntity): | ||
|
||
def __init__(self, name, device): | ||
super().__init__("child_Lock", name, device) | ||
self._state: bool = None | ||
self._attr_icon = "mdi:account-child-outline" | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
"""Return true if the binary sensor is on.""" | ||
return self._device.child_lock | ||
|
||
|
||
class BlueairOnlineSensor(BlueairEntity, BinarySensorEntity): | ||
def __init__(self, name, device): | ||
"""Initialize the online sensor.""" | ||
super().__init__("online", name, device) | ||
self._state: bool = None | ||
self._attr_icon = "mdi:wifi-check" | ||
self._attr_device_class = BinarySensorDeviceClass.CONNECTIVITY, | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
"""Return true if the binary sensor is on.""" | ||
return self._device.wifi_working | ||
|
||
@property | ||
def icon(self) -> str | None: | ||
if self.is_on: | ||
return self._attr_icon | ||
else: | ||
return "mdi:wifi-strength-outline" |
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
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,60 @@ | ||
from .const import DOMAIN | ||
from .device import BlueairDataUpdateCoordinator | ||
from .entity import BlueairEntity | ||
from homeassistant.components.light import ( | ||
ATTR_BRIGHTNESS, | ||
ColorMode, | ||
LightEntity, | ||
) | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Set up the Blueair sensors from config entry.""" | ||
devices: list[BlueairDataUpdateCoordinator] = hass.data[DOMAIN][ | ||
config_entry.entry_id | ||
]["devices"] | ||
entities = [] | ||
for device in devices: | ||
# Don't add sensors to classic models | ||
if ( | ||
device.model.startswith("classic") and not device.model.endswith("i") | ||
) or device.model == "foobot": | ||
pass | ||
else: | ||
entities.extend( | ||
[ | ||
BlueairLightEntity(f"{device.device_name}_light", device), | ||
] | ||
) | ||
async_add_entities(entities) | ||
|
||
|
||
class BlueairLightEntity(BlueairEntity, LightEntity): | ||
_attr_color_mode = ColorMode.BRIGHTNESS | ||
_attr_supported_color_modes = {ColorMode.BRIGHTNESS} | ||
|
||
def __init__(self, name, device): | ||
super().__init__("LED Light", name, device) | ||
|
||
@property | ||
def brightness(self) -> int | None: | ||
"""Return the brightness of this light between 0..255.""" | ||
return round(self._device.brightness / 100 * 255.0, 0) | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return True if the entity is on.""" | ||
return self._device.brightness != 0 | ||
|
||
async def async_turn_on(self, **kwargs): | ||
if ATTR_BRIGHTNESS in kwargs: | ||
# Convert Home Assistant brightness (0-255) to Abode brightness (0-99) | ||
# If 100 is sent to Abode, response is 99 causing an error | ||
await self._device.set_brightness( | ||
round(kwargs[ATTR_BRIGHTNESS] * 100 / 255.0) | ||
) | ||
else: | ||
await self._device.set_brightness(100) | ||
|
||
async def async_turn_off(self, **kwargs): | ||
await self._device.set_brightness(0) |
Oops, something went wrong.