1 """Platform for switch integration."""
3 from __future__
import annotations
7 from triggercmd
import client, ha
14 from .
import TriggercmdConfigEntry
15 from .const
import DOMAIN
17 _LOGGER = logging.getLogger(__name__)
22 config_entry: TriggercmdConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Add switch for passed config_entry in HA."""
26 hub = config_entry.runtime_data
31 """Representation of a Switch."""
33 _attr_has_entity_name =
True
34 _attr_assumed_state =
True
35 _attr_should_poll =
False
43 def __init__(self, trigger: TRIGGERcmdSwitch) ->
None:
44 """Initialize the switch."""
47 self.
_attr_unique_id_attr_unique_id = f
"{trigger.computer_id}.{trigger.trigger_id}"
50 identifiers={(DOMAIN, trigger.computer_id)},
51 name=trigger.computer_id.capitalize(),
52 sw_version=trigger.firmware_version,
54 manufacturer=trigger.hub.manufacturer,
59 """Return True if hub is available."""
60 return self.
_switch_switch.hub.online
63 """Turn the switch on."""
69 """Turn the switch off."""
70 await self.
triggertrigger(
"off")
75 """Trigger the command."""
76 r = await client.async_trigger(
79 "computer": self.
_switch_switch.computer_id,
80 "trigger": self.
_switch_switch.trigger_id,
82 "sender":
"Home Assistant",
85 _LOGGER.debug(
"TRIGGERcmd trigger response: %s", r.json())
def async_turn_off(self, **kwargs)
None __init__(self, TRIGGERcmdSwitch trigger)
def async_turn_on(self, **kwargs)
def trigger(self, str params)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, TriggercmdConfigEntry config_entry, AddEntitiesCallback async_add_entities)