1 """Switch implementation for Wireless Sensor Tags (wirelesstag.net)."""
3 from __future__
import annotations
7 import voluptuous
as vol
10 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
12 SwitchEntityDescription,
20 from .const
import DOMAIN
21 from .entity
import WirelessTagBaseSensor
22 from .util
import async_migrate_unique_id
24 SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
27 name=
"Arm Temperature",
47 SWITCH_KEYS: list[str] = [desc.key
for desc
in SWITCH_TYPES]
49 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
51 vol.Required(CONF_MONITORED_CONDITIONS, default=[]): vol.All(
52 cv.ensure_list, [vol.In(SWITCH_KEYS)]
61 async_add_entities: AddEntitiesCallback,
62 discovery_info: DiscoveryInfoType |
None =
None,
64 """Set up switches for a Wireless Sensor Tags."""
65 platform = hass.data[DOMAIN]
67 tags = platform.load_tags()
68 monitored_conditions = config[CONF_MONITORED_CONDITIONS]
70 for tag
in tags.values():
71 for description
in SWITCH_TYPES:
73 description.key
in monitored_conditions
74 and description.key
in tag.allowed_monitoring_types
83 """A switch implementation for Wireless Sensor Tags."""
85 def __init__(self, api, tag, description: SwitchEntityDescription) ->
None:
86 """Initialize a switch for Wireless Sensor Tag."""
89 self.
_name_name_name = f
"{self._tag.name} {description.name}"
93 """Turn on the switch."""
94 self.
_api_api.arm(self)
97 """Turn on the switch."""
98 self.
_api_api.disarm(self)
102 """Return True if entity is on."""
106 """Provide formatted value."""
111 """Provide actual value of switch."""
112 attr_name = f
"is_{self.entity_description.key}_sensor_armed"
113 return getattr(self.
_tag_tag, attr_name,
False)
def principal_value(self)
None async_migrate_unique_id(HomeAssistant hass, ConfigEntry config_entry, Appliance device)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)