mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Ecobee: Report Humidifier Action (#138756)
Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
parent
c48797804d
commit
82ac3e3fdf
@ -3,11 +3,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.humidifier import (
|
from homeassistant.components.humidifier import (
|
||||||
DEFAULT_MAX_HUMIDITY,
|
DEFAULT_MAX_HUMIDITY,
|
||||||
DEFAULT_MIN_HUMIDITY,
|
DEFAULT_MIN_HUMIDITY,
|
||||||
MODE_AUTO,
|
MODE_AUTO,
|
||||||
|
HumidifierAction,
|
||||||
HumidifierDeviceClass,
|
HumidifierDeviceClass,
|
||||||
HumidifierEntity,
|
HumidifierEntity,
|
||||||
HumidifierEntityFeature,
|
HumidifierEntityFeature,
|
||||||
@ -41,6 +43,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
|
||||||
|
ECOBEE_HUMIDIFIER_ACTION_TO_HASS = {
|
||||||
|
"humidifier": HumidifierAction.HUMIDIFYING,
|
||||||
|
"dehumidifier": HumidifierAction.DRYING,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class EcobeeHumidifier(HumidifierEntity):
|
class EcobeeHumidifier(HumidifierEntity):
|
||||||
"""A humidifier class for an ecobee thermostat with humidifier attached."""
|
"""A humidifier class for an ecobee thermostat with humidifier attached."""
|
||||||
|
|
||||||
@ -52,7 +60,7 @@ class EcobeeHumidifier(HumidifierEntity):
|
|||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(self, data, thermostat_index):
|
def __init__(self, data, thermostat_index) -> None:
|
||||||
"""Initialize ecobee humidifier platform."""
|
"""Initialize ecobee humidifier platform."""
|
||||||
self.data = data
|
self.data = data
|
||||||
self.thermostat_index = thermostat_index
|
self.thermostat_index = thermostat_index
|
||||||
@ -80,11 +88,11 @@ class EcobeeHumidifier(HumidifierEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self) -> bool:
|
||||||
"""Return if device is available."""
|
"""Return if device is available."""
|
||||||
return self.thermostat["runtime"]["connected"]
|
return self.thermostat["runtime"]["connected"]
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self) -> None:
|
||||||
"""Get the latest state from the thermostat."""
|
"""Get the latest state from the thermostat."""
|
||||||
if self.update_without_throttle:
|
if self.update_without_throttle:
|
||||||
await self.data.update(no_throttle=True)
|
await self.data.update(no_throttle=True)
|
||||||
@ -96,12 +104,20 @@ class EcobeeHumidifier(HumidifierEntity):
|
|||||||
self._last_humidifier_on_mode = self.mode
|
self._last_humidifier_on_mode = self.mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def action(self) -> HumidifierAction:
|
||||||
|
"""Return the current action."""
|
||||||
|
for status in self.thermostat["equipmentStatus"].split(","):
|
||||||
|
if status in ECOBEE_HUMIDIFIER_ACTION_TO_HASS:
|
||||||
|
return ECOBEE_HUMIDIFIER_ACTION_TO_HASS[status]
|
||||||
|
return HumidifierAction.IDLE if self.is_on else HumidifierAction.OFF
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
"""Return True if the humidifier is on."""
|
"""Return True if the humidifier is on."""
|
||||||
return self.mode != MODE_OFF
|
return self.mode != MODE_OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mode(self):
|
def mode(self) -> str:
|
||||||
"""Return the current mode, e.g., off, auto, manual."""
|
"""Return the current mode, e.g., off, auto, manual."""
|
||||||
return self.thermostat["settings"]["humidifierMode"]
|
return self.thermostat["settings"]["humidifierMode"]
|
||||||
|
|
||||||
@ -118,9 +134,11 @@ class EcobeeHumidifier(HumidifierEntity):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_mode(self, mode):
|
def set_mode(self, mode: str) -> None:
|
||||||
"""Set humidifier mode (auto, off, manual)."""
|
"""Set humidifier mode (auto, off, manual)."""
|
||||||
if mode.lower() not in (self.available_modes):
|
if self.available_modes is None:
|
||||||
|
raise NotImplementedError("Humidifier does not support modes.")
|
||||||
|
if mode.lower() not in self.available_modes:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid mode value: {mode} Valid values are"
|
f"Invalid mode value: {mode} Valid values are"
|
||||||
f" {', '.join(self.available_modes)}."
|
f" {', '.join(self.available_modes)}."
|
||||||
@ -134,10 +152,10 @@ class EcobeeHumidifier(HumidifierEntity):
|
|||||||
self.data.ecobee.set_humidity(self.thermostat_index, humidity)
|
self.data.ecobee.set_humidity(self.thermostat_index, humidity)
|
||||||
self.update_without_throttle = True
|
self.update_without_throttle = True
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Set humidifier to off mode."""
|
"""Set humidifier to off mode."""
|
||||||
self.set_mode(MODE_OFF)
|
self.set_mode(MODE_OFF)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Set humidifier to on mode."""
|
"""Set humidifier to on mode."""
|
||||||
self.set_mode(self._last_humidifier_on_mode)
|
self.set_mode(self._last_humidifier_on_mode)
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
"hasHeatPump": false,
|
"hasHeatPump": false,
|
||||||
"humidity": "30"
|
"humidity": "30"
|
||||||
},
|
},
|
||||||
"equipmentStatus": "fan",
|
"equipmentStatus": "fan,humidifier",
|
||||||
"events": [
|
"events": [
|
||||||
{
|
{
|
||||||
"name": "Event1",
|
"name": "Event1",
|
||||||
|
@ -6,6 +6,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant.components.ecobee.humidifier import MODE_MANUAL, MODE_OFF
|
from homeassistant.components.ecobee.humidifier import MODE_MANUAL, MODE_OFF
|
||||||
from homeassistant.components.humidifier import (
|
from homeassistant.components.humidifier import (
|
||||||
|
ATTR_ACTION,
|
||||||
ATTR_AVAILABLE_MODES,
|
ATTR_AVAILABLE_MODES,
|
||||||
ATTR_CURRENT_HUMIDITY,
|
ATTR_CURRENT_HUMIDITY,
|
||||||
ATTR_HUMIDITY,
|
ATTR_HUMIDITY,
|
||||||
@ -17,6 +18,7 @@ from homeassistant.components.humidifier import (
|
|||||||
MODE_AUTO,
|
MODE_AUTO,
|
||||||
SERVICE_SET_HUMIDITY,
|
SERVICE_SET_HUMIDITY,
|
||||||
SERVICE_SET_MODE,
|
SERVICE_SET_MODE,
|
||||||
|
HumidifierAction,
|
||||||
HumidifierDeviceClass,
|
HumidifierDeviceClass,
|
||||||
HumidifierEntityFeature,
|
HumidifierEntityFeature,
|
||||||
)
|
)
|
||||||
@ -44,6 +46,7 @@ async def test_attributes(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
state = hass.states.get(DEVICE_ID)
|
state = hass.states.get(DEVICE_ID)
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
assert state.attributes[ATTR_ACTION] == HumidifierAction.HUMIDIFYING
|
||||||
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 15
|
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 15
|
||||||
assert state.attributes[ATTR_MIN_HUMIDITY] == DEFAULT_MIN_HUMIDITY
|
assert state.attributes[ATTR_MIN_HUMIDITY] == DEFAULT_MIN_HUMIDITY
|
||||||
assert state.attributes[ATTR_MAX_HUMIDITY] == DEFAULT_MAX_HUMIDITY
|
assert state.attributes[ATTR_MAX_HUMIDITY] == DEFAULT_MAX_HUMIDITY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user