-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Humidifier platform support (#170)
feat: Add support for humidifier platform * Support for target humidity / aka auto regulated humidity * Add support for humidifier platform * Address feedback * Revert manifest.json change * Add not implemented abstract methods for consistency * Fix missing localisation * change target_humidity / auto_regulated_humidity naming * chore: remove should poll as it is already provided by BaseCoordinatorEntity * fix: int_cast aware of None and NotImplemented (#173) This change intends to fix #169. * chore: bumping version to 1.17.10 * linting address feedback move static properties to init * Revert "chore: remove should poll as it is already provided by BaseCoordinatorEntity" This reverts commit ed54237. * Change 'normal mode' to 'fan speed mode' * Remove wonky Dry Wick mode --------- Co-authored-by: zim514 <krisyoung@gmail.com> Co-authored-by: Brendan Dahl <dahl.brendan@gmail.com> Co-authored-by: Yu Feng <rainwoodman@gmail.com> Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
d920ed5
commit 866baf1
Showing
7 changed files
with
176 additions
and
1 deletion.
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
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,122 @@ | ||
"""Support for Blueair humidifiers.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from homeassistant.components.humidifier import ( | ||
MODE_AUTO, | ||
MODE_SLEEP, | ||
HumidifierDeviceClass, | ||
HumidifierEntity, | ||
HumidifierEntityFeature, | ||
) | ||
|
||
from .blueair_update_coordinator_device_aws import BlueairUpdateCoordinator | ||
from .const import MODE_FAN_SPEED | ||
from .entity import BlueairEntity, async_setup_entry_helper | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Set up the Blueair humidifier from config entry""" | ||
|
||
async_setup_entry_helper( | ||
hass, | ||
config_entry, | ||
async_add_entities, | ||
entity_classes=[ | ||
BlueairAwsHumidifier, | ||
], | ||
) | ||
|
||
|
||
class BlueairAwsHumidifier(BlueairEntity, HumidifierEntity): | ||
"""Controls Humidifier.""" | ||
|
||
@classmethod | ||
def is_implemented(kls, coordinator): | ||
return coordinator.auto_regulated_humidity is not NotImplemented | ||
|
||
def __init__(self, coordinator: BlueairUpdateCoordinator): | ||
"""Initialize the humidifer.""" | ||
self._attr_device_class = HumidifierDeviceClass.HUMIDIFIER | ||
self._attr_supported_features = HumidifierEntityFeature.MODES | ||
self._attr_translation_key = "ha_blueair" | ||
self._attr_available_modes = [ | ||
MODE_AUTO, | ||
MODE_SLEEP, | ||
MODE_FAN_SPEED, | ||
] | ||
super().__init__("Humidifier", coordinator) | ||
|
||
@property | ||
def available(self) -> bool: | ||
"""Return if entity is available.""" | ||
return self.coordinator.last_update_success and self.coordinator.online | ||
|
||
@property | ||
def mode(self): | ||
if self.coordinator.night_mode: | ||
return MODE_SLEEP | ||
elif self.coordinator.fan_auto_mode: | ||
return MODE_AUTO | ||
elif self.is_on: | ||
return MODE_FAN_SPEED | ||
else: | ||
return | ||
|
||
@property | ||
def is_on(self) -> int: | ||
return self.coordinator.is_on | ||
|
||
@property | ||
def target_humidity(self): | ||
return self.coordinator.auto_regulated_humidity | ||
|
||
@property | ||
def current_humidity(self): | ||
return self.coordinator.humidity | ||
|
||
async def async_turn_off(self, **kwargs: any) -> None: | ||
await self.coordinator.set_running(False) | ||
self.async_write_ha_state() | ||
|
||
async def async_turn_on( | ||
self, | ||
percentage: int | None = None, | ||
preset_mode: str | None = None, | ||
**kwargs: any, | ||
) -> None: | ||
await self.coordinator.set_running(True) | ||
self.async_write_ha_state() | ||
|
||
async def async_set_mode(self, mode): | ||
if mode == MODE_AUTO: | ||
# This mode doesn't apply when off | ||
await self.coordinator.set_fan_auto_mode(True) | ||
await self.coordinator.set_running(True) | ||
self.async_write_ha_state() | ||
elif mode == MODE_SLEEP: | ||
# This mode doesn't apply when off | ||
await self.coordinator.set_night_mode(True) | ||
await self.coordinator.set_fan_auto_mode(False) | ||
await self.coordinator.set_running(False) | ||
self.async_write_ha_state() | ||
elif mode == MODE_FAN_SPEED: | ||
# This mode doesn't apply when off | ||
await self.coordinator.set_fan_auto_mode(False) | ||
await self.coordinator.set_night_mode(False) | ||
await self.coordinator.set_running(True) | ||
|
||
self.async_write_ha_state() | ||
else: | ||
raise ValueError(f"Invalid mode: {mode}") | ||
|
||
async def async_set_humidity(self, humidity): | ||
"""Set the humidity level. Sets Humidifier to 'On' to comply with hass requirements, and sets mode to Auto since this is the only mode in which the target humidity is used.""" | ||
|
||
await self.coordinator.set_auto_regulated_humidity(humidity) | ||
await self.coordinator.set_fan_auto_mode(True) | ||
await self.async_turn_on() |
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