mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 23:37:18 +00:00
Add select platform to Plugwise (#68303)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
1f135a20a0
commit
574f4710aa
@ -898,6 +898,7 @@ omit =
|
|||||||
homeassistant/components/plaato/sensor.py
|
homeassistant/components/plaato/sensor.py
|
||||||
homeassistant/components/plex/media_player.py
|
homeassistant/components/plex/media_player.py
|
||||||
homeassistant/components/plex/view.py
|
homeassistant/components/plex/view.py
|
||||||
|
homeassistant/components/plugwise/select.py
|
||||||
homeassistant/components/plum_lightpad/light.py
|
homeassistant/components/plum_lightpad/light.py
|
||||||
homeassistant/components/pocketcasts/sensor.py
|
homeassistant/components/pocketcasts/sensor.py
|
||||||
homeassistant/components/point/__init__.py
|
homeassistant/components/point/__init__.py
|
||||||
|
@ -21,18 +21,11 @@ from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN
|
from .const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN, THERMOSTAT_CLASSES
|
||||||
from .coordinator import PlugwiseDataUpdateCoordinator
|
from .coordinator import PlugwiseDataUpdateCoordinator
|
||||||
from .entity import PlugwiseEntity
|
from .entity import PlugwiseEntity
|
||||||
from .util import plugwise_command
|
from .util import plugwise_command
|
||||||
|
|
||||||
THERMOSTAT_CLASSES = [
|
|
||||||
"thermostat",
|
|
||||||
"thermostatic_radiator_valve",
|
|
||||||
"zone_thermometer",
|
|
||||||
"zone_thermostat",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -24,6 +24,7 @@ PLATFORMS_GATEWAY = [
|
|||||||
Platform.CLIMATE,
|
Platform.CLIMATE,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
|
Platform.SELECT,
|
||||||
]
|
]
|
||||||
ZEROCONF_MAP = {
|
ZEROCONF_MAP = {
|
||||||
"smile": "P1",
|
"smile": "P1",
|
||||||
@ -43,3 +44,10 @@ DEFAULT_SCAN_INTERVAL = {
|
|||||||
"thermostat": timedelta(seconds=60),
|
"thermostat": timedelta(seconds=60),
|
||||||
}
|
}
|
||||||
DEFAULT_USERNAME = "smile"
|
DEFAULT_USERNAME = "smile"
|
||||||
|
|
||||||
|
THERMOSTAT_CLASSES = [
|
||||||
|
"thermostat",
|
||||||
|
"thermostatic_radiator_valve",
|
||||||
|
"zone_thermometer",
|
||||||
|
"zone_thermostat",
|
||||||
|
]
|
||||||
|
64
homeassistant/components/plugwise/select.py
Normal file
64
homeassistant/components/plugwise/select.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
"""Plugwise Select component for Home Assistant."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from homeassistant.components.select import SelectEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import STATE_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import DOMAIN, THERMOSTAT_CLASSES
|
||||||
|
from .coordinator import PlugwiseDataUpdateCoordinator
|
||||||
|
from .entity import PlugwiseEntity
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up the Smile selector from a config entry."""
|
||||||
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
async_add_entities(
|
||||||
|
PlugwiseSelectEntity(coordinator, device_id)
|
||||||
|
for device_id, device in coordinator.data.devices.items()
|
||||||
|
if device["class"] in THERMOSTAT_CLASSES
|
||||||
|
and len(device.get("available_schedules")) > 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PlugwiseSelectEntity(PlugwiseEntity, SelectEntity):
|
||||||
|
"""Represent Smile selector."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: PlugwiseDataUpdateCoordinator,
|
||||||
|
device_id: str,
|
||||||
|
) -> None:
|
||||||
|
"""Initialise the selector."""
|
||||||
|
super().__init__(coordinator, device_id)
|
||||||
|
self._attr_unique_id = f"{device_id}-select_schedule"
|
||||||
|
self._attr_name = (f"{self.device.get('name', '')} Select Schedule").lstrip()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_option(self) -> str | None:
|
||||||
|
"""Return the selected entity option to represent the entity state."""
|
||||||
|
return self.device.get("selected_schedule")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def options(self) -> list[str]:
|
||||||
|
"""Return a set of selectable options."""
|
||||||
|
return self.device.get("available_schedules", [])
|
||||||
|
|
||||||
|
async def async_select_option(self, option: str) -> None:
|
||||||
|
"""Change the selected option."""
|
||||||
|
if not (
|
||||||
|
await self.coordinator.api.set_schedule_state(
|
||||||
|
self.device.get("location"),
|
||||||
|
option,
|
||||||
|
STATE_ON,
|
||||||
|
)
|
||||||
|
):
|
||||||
|
raise HomeAssistantError(f"Failed to change to schedule {option}")
|
||||||
|
await self.coordinator.async_request_refresh()
|
Loading…
x
Reference in New Issue
Block a user