1 """Support for ESPHome switches."""
3 from __future__
import annotations
5 from functools
import partial
8 from aioesphomeapi
import EntityInfo, SwitchInfo, SwitchState
16 convert_api_error_ha_error,
17 esphome_state_property,
18 platform_async_setup_entry,
23 """A switch implementation for ESPHome."""
27 """Set attrs from static info."""
32 SwitchDeviceClass, static_info.device_class
36 @esphome_state_property
38 """Return true if the switch is on."""
39 return self.
_state_state.state
41 @convert_api_error_ha_error
43 """Turn the entity on."""
44 self.
_client_client.switch_command(self.
_key_key,
True)
46 @convert_api_error_ha_error
48 """Turn the entity off."""
49 self.
_client_client.switch_command(self.
_key_key,
False)
52 async_setup_entry = partial(
53 platform_async_setup_entry,
55 entity_type=EsphomeSwitch,
56 state_type=SwitchState,
None _on_static_info_update(self, EntityInfo static_info)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)