|
1 | 1 | """Switch platform for MyHeat."""
|
2 | 2 |
|
3 | 3 | from homeassistant.components.switch import SwitchEntity
|
| 4 | +from homeassistant.config_entries import ConfigEntry |
| 5 | +from homeassistant.core import HomeAssistant |
| 6 | +from homeassistant.helpers.entity_platform import AddEntitiesCallback |
4 | 7 |
|
5 |
| -from .const import DEFAULT_NAME |
6 | 8 | from .const import DOMAIN
|
7 |
| -from .const import ICON |
8 |
| -from .const import SWITCH |
9 | 9 | from .entity import MhEntity
|
10 | 10 |
|
11 | 11 |
|
12 |
| -async def async_setup_entry(hass, entry, async_add_devices): |
| 12 | +async def async_setup_entry( |
| 13 | + hass: HomeAssistant, |
| 14 | + entry: ConfigEntry, |
| 15 | + async_add_devices: AddEntitiesCallback, |
| 16 | +): |
13 | 17 | """Setup sensor platform."""
|
14 | 18 | coordinator = hass.data[DOMAIN][entry.entry_id]
|
15 |
| - async_add_devices([MhBinarySwitch(coordinator, entry)]) |
| 19 | + async_add_devices([MhSecuritySwitch(coordinator, entry)]) |
16 | 20 |
|
17 | 21 |
|
18 |
| -class MhBinarySwitch(MhEntity, SwitchEntity): |
| 22 | +class MhSecuritySwitch(MhEntity, SwitchEntity): |
19 | 23 | """myheat switch class."""
|
20 | 24 |
|
21 |
| - async def async_turn_on(self, **kwargs): # pylint: disable=unused-argument |
22 |
| - """Turn on the switch.""" |
23 |
| - await self.coordinator.api.async_set_title("bar") |
24 |
| - await self.coordinator.async_request_refresh() |
25 |
| - |
26 |
| - async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument |
27 |
| - """Turn off the switch.""" |
28 |
| - await self.coordinator.api.async_set_title("foo") |
29 |
| - await self.coordinator.async_request_refresh() |
| 25 | + _attr_icon = "mdi:security" |
30 | 26 |
|
31 | 27 | @property
|
32 |
| - def name(self): |
33 |
| - """Return the name of the switch.""" |
34 |
| - return f"{DEFAULT_NAME}_{SWITCH}" |
| 28 | + def name(self) -> str: |
| 29 | + return f"{self._mh_name} security alarm" |
35 | 30 |
|
36 | 31 | @property
|
37 |
| - def icon(self): |
38 |
| - """Return the icon of this switch.""" |
39 |
| - return ICON |
| 32 | + def unique_id(self) -> str: |
| 33 | + return f"{super().unique_id}security" |
40 | 34 |
|
41 |
| - @property |
42 |
| - def is_on(self): |
43 |
| - """Return true if the switch is on.""" |
44 |
| - return self.coordinator.data.get("title", "") == "foo" |
| 35 | + async def async_turn_on(self, **kwargs): # pylint: disable=unused-argument |
| 36 | + await self.coordinator.api.async_set_security_mode(mode=True) |
| 37 | + # NOTE: we cannot query the state, so we have to make some assumptions |
| 38 | + self._attr_is_on = True |
| 39 | + |
| 40 | + async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument |
| 41 | + await self.coordinator.api.async_set_security_mode(mode=False) |
| 42 | + self._attr_is_on = False |
0 commit comments