mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Add select platform to senseme (#64086)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
b52a8ba37a
commit
b064a24123
@ -20,4 +20,10 @@ PRESET_MODE_WHOOSH = "Whoosh"
|
|||||||
SENSEME_DIRECTION_FORWARD = "FWD"
|
SENSEME_DIRECTION_FORWARD = "FWD"
|
||||||
SENSEME_DIRECTION_REVERSE = "REV"
|
SENSEME_DIRECTION_REVERSE = "REV"
|
||||||
|
|
||||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.FAN, Platform.SWITCH]
|
PLATFORMS = [
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
|
Platform.FAN,
|
||||||
|
Platform.LIGHT,
|
||||||
|
Platform.SELECT,
|
||||||
|
Platform.SWITCH,
|
||||||
|
]
|
||||||
|
@ -76,14 +76,6 @@ class HASensemeFan(SensemeEntity, FanEntity):
|
|||||||
self._attr_preset_mode = whoosh if whoosh else None
|
self._attr_preset_mode = whoosh if whoosh else None
|
||||||
super()._async_update_attrs()
|
super()._async_update_attrs()
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self) -> dict:
|
|
||||||
"""Get the current device state attributes."""
|
|
||||||
return {
|
|
||||||
"auto_comfort": self._device.fan_autocomfort.capitalize(),
|
|
||||||
"smartmode": self._device.fan_smartmode.capitalize(),
|
|
||||||
}
|
|
||||||
|
|
||||||
async def async_set_percentage(self, percentage: int) -> None:
|
async def async_set_percentage(self, percentage: int) -> None:
|
||||||
"""Set the speed of the fan, as a percentage."""
|
"""Set the speed of the fan, as a percentage."""
|
||||||
self._device.fan_speed = math.ceil(
|
self._device.fan_speed = math.ceil(
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/senseme",
|
"documentation": "https://www.home-assistant.io/integrations/senseme",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"aiosenseme==0.5.5"
|
"aiosenseme==0.6.0"
|
||||||
],
|
],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@mikelawrence", "@bdraco"
|
"@mikelawrence", "@bdraco"
|
||||||
],
|
],
|
||||||
"iot_class": "local_push"
|
"iot_class": "local_push"
|
||||||
}
|
}
|
||||||
|
90
homeassistant/components/senseme/select.py
Normal file
90
homeassistant/components/senseme/select.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
"""Support for Big Ass Fans SenseME selects."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from aiosenseme import SensemeFan
|
||||||
|
from aiosenseme.device import SensemeDevice
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .entity import SensemeEntity
|
||||||
|
|
||||||
|
SMART_MODE_TO_HASS = {
|
||||||
|
"OFF": "Off",
|
||||||
|
"COOLING": "Cooling",
|
||||||
|
"HEATING": "Heating",
|
||||||
|
"FOLLOWTSTAT": "Follow Thermostat",
|
||||||
|
}
|
||||||
|
HASS_TO_SMART_MODE = {v: k for k, v in SMART_MODE_TO_HASS.items()}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SenseMESelectEntityDescriptionMixin:
|
||||||
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
|
value_fn: Callable[[SensemeFan], str]
|
||||||
|
set_fn: Callable[[SensemeFan, str], None]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SenseMESelectEntityDescription(
|
||||||
|
SelectEntityDescription, SenseMESelectEntityDescriptionMixin
|
||||||
|
):
|
||||||
|
"""Describes SenseME select entity."""
|
||||||
|
|
||||||
|
|
||||||
|
def _set_smart_mode(device: SensemeDevice, value: str) -> None:
|
||||||
|
device.fan_smartmode = HASS_TO_SMART_MODE[value]
|
||||||
|
|
||||||
|
|
||||||
|
FAN_SELECTS = [
|
||||||
|
SenseMESelectEntityDescription(
|
||||||
|
key="smart_mode",
|
||||||
|
name="Smart Mode",
|
||||||
|
value_fn=lambda device: SMART_MODE_TO_HASS[device.fan_smartmode],
|
||||||
|
set_fn=_set_smart_mode,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: config_entries.ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up SenseME fan selects."""
|
||||||
|
device = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
if device.is_fan:
|
||||||
|
async_add_entities(
|
||||||
|
HASensemeSelect(device, description) for description in FAN_SELECTS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class HASensemeSelect(SensemeEntity, SelectEntity):
|
||||||
|
"""SenseME select component."""
|
||||||
|
|
||||||
|
entity_description: SenseMESelectEntityDescription
|
||||||
|
_attr_options = list(SMART_MODE_TO_HASS.values())
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, device: SensemeFan, description: SenseMESelectEntityDescription
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the entity."""
|
||||||
|
self.entity_description = description
|
||||||
|
super().__init__(device, f"{device.name} {description.name}")
|
||||||
|
self._attr_unique_id = f"{self._device.uuid}-{description.key}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_option(self) -> str:
|
||||||
|
"""Return the current value."""
|
||||||
|
return self.entity_description.value_fn(self._device)
|
||||||
|
|
||||||
|
async def async_select_option(self, option: str) -> None:
|
||||||
|
"""Set the option."""
|
||||||
|
self.entity_description.set_fn(self._device, option)
|
@ -254,7 +254,7 @@ aiorecollect==1.0.8
|
|||||||
aioridwell==2021.12.2
|
aioridwell==2021.12.2
|
||||||
|
|
||||||
# homeassistant.components.senseme
|
# homeassistant.components.senseme
|
||||||
aiosenseme==0.5.5
|
aiosenseme==0.6.0
|
||||||
|
|
||||||
# homeassistant.components.shelly
|
# homeassistant.components.shelly
|
||||||
aioshelly==1.0.7
|
aioshelly==1.0.7
|
||||||
|
@ -186,7 +186,7 @@ aiorecollect==1.0.8
|
|||||||
aioridwell==2021.12.2
|
aioridwell==2021.12.2
|
||||||
|
|
||||||
# homeassistant.components.senseme
|
# homeassistant.components.senseme
|
||||||
aiosenseme==0.5.5
|
aiosenseme==0.6.0
|
||||||
|
|
||||||
# homeassistant.components.shelly
|
# homeassistant.components.shelly
|
||||||
aioshelly==1.0.7
|
aioshelly==1.0.7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user