-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.py
94 lines (73 loc) · 3.06 KB
/
select.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Select entities for Wyoming integration."""
from __future__ import annotations
from typing import TYPE_CHECKING, Final
from homeassistant.components.assist_pipeline.select import AssistPipelineSelect
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers import restore_state
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .devices import SatelliteDevice
from .entity import WyomingSatelliteEntity
if TYPE_CHECKING:
from .models import DomainDataItem
_NOISE_SUPPRESSION_LEVEL: Final = {
"off": 0,
"low": 1,
"medium": 2,
"high": 3,
"max": 4,
}
_DEFAULT_NOISE_SUPPRESSION_LEVEL: Final = "off"
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Wyoming select entities."""
item: DomainDataItem = hass.data[DOMAIN][config_entry.entry_id]
# Setup is only forwarded for satellites
assert item.satellite is not None
device = item.satellite.device
async_add_entities(
[
WyomingSatellitePipelineSelect(hass, device),
WyomingSatelliteNoiseSuppressionLevelSelect(device),
]
)
class WyomingSatellitePipelineSelect(WyomingSatelliteEntity, AssistPipelineSelect):
"""Pipeline selector for Wyoming satellites."""
def __init__(self, hass: HomeAssistant, device: SatelliteDevice) -> None:
"""Initialize a pipeline selector."""
self.device = device
WyomingSatelliteEntity.__init__(self, device)
AssistPipelineSelect.__init__(self, hass, device.satellite_id)
async def async_select_option(self, option: str) -> None:
"""Select an option."""
await super().async_select_option(option)
self.device.set_pipeline_name(option)
class WyomingSatelliteNoiseSuppressionLevelSelect(
WyomingSatelliteEntity, SelectEntity, restore_state.RestoreEntity
):
"""Entity to represent noise suppression level setting."""
entity_description = SelectEntityDescription(
key="noise_suppression_level",
translation_key="noise_suppression_level",
entity_category=EntityCategory.CONFIG,
)
_attr_should_poll = False
_attr_current_option = _DEFAULT_NOISE_SUPPRESSION_LEVEL
_attr_options = list(_NOISE_SUPPRESSION_LEVEL.keys())
async def async_added_to_hass(self) -> None:
"""When entity is added to Home Assistant."""
await super().async_added_to_hass()
state = await self.async_get_last_state()
if state is not None and state.state in self.options:
self._attr_current_option = state.state
async def async_select_option(self, option: str) -> None:
"""Select an option."""
self._attr_current_option = option
self.async_write_ha_state()
self._device.set_noise_suppression_level(_NOISE_SUPPRESSION_LEVEL[option])