1 """Nice G.O. switch platform."""
3 from __future__
import annotations
6 from typing
import TYPE_CHECKING, Any
8 from aiohttp
import ClientError
9 from nice_go
import ApiError
17 from .
import NiceGOConfigEntry
20 KNOWN_UNSUPPORTED_DEVICE_TYPES,
21 SUPPORTED_DEVICE_TYPES,
22 UNSUPPORTED_DEVICE_WARNING,
24 from .entity
import NiceGOEntity
26 _LOGGER = logging.getLogger(__name__)
31 config_entry: NiceGOConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Set up Nice G.O. switch."""
35 coordinator = config_entry.runtime_data
39 for device_id, device_data
in coordinator.data.items():
40 if device_data.type
in SUPPORTED_DEVICE_TYPES[Platform.SWITCH]:
44 elif device_data.type
not in KNOWN_UNSUPPORTED_DEVICE_TYPES[Platform.SWITCH]:
46 UNSUPPORTED_DEVICE_WARNING,
56 """Representation of a Nice G.O. switch."""
58 _attr_device_class = SwitchDeviceClass.SWITCH
59 _attr_translation_key =
"vacation_mode"
63 """Return if switch is on."""
65 assert self.
datadatadata.vacation_mode
is not None
66 return self.
datadatadata.vacation_mode
69 """Turn the switch on."""
72 await self.coordinator.api.vacation_mode_on(self.
datadatadata.id)
73 except (ApiError, ClientError)
as error:
75 translation_domain=DOMAIN,
76 translation_key=
"switch_on_error",
77 translation_placeholders={
"exception":
str(error)},
81 """Turn the switch off."""
84 await self.coordinator.api.vacation_mode_off(self.
datadatadata.id)
85 except (ApiError, ClientError)
as error:
87 translation_domain=DOMAIN,
88 translation_key=
"switch_off_error",
89 translation_placeholders={
"exception":
str(error)},
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, NiceGOConfigEntry config_entry, AddEntitiesCallback async_add_entities)