1 """Support for Powerwall Switches (V2 API only)."""
5 from tesla_powerwall
import GridStatus, IslandMode, PowerwallError
13 from .entity
import PowerWallEntity
14 from .models
import PowerwallConfigEntry, PowerwallRuntimeData
17 GridStatus.TRANSITION_TO_ISLAND,
24 entry: PowerwallConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up Powerwall switch platform from Powerwall resources."""
32 """Representation of a Switch entity for Powerwall Off-grid operation."""
34 _attr_translation_key =
"off_grid_operation"
35 _attr_entity_category = EntityCategory.CONFIG
36 _attr_device_class = SwitchDeviceClass.SWITCH
38 def __init__(self, powerwall_data: PowerwallRuntimeData) ->
None:
39 """Initialize powerwall entity and unique id."""
45 """Return true if the powerwall is off-grid."""
46 return self.coordinator.data.grid_status
in OFF_GRID_STATUSES
49 """Turn off-grid mode on."""
53 """Turn off-grid mode off (return to on-grid usage)."""
57 """Toggles off-grid mode using the island_mode argument."""
59 await self.
power_wallpower_wall.set_island_mode(island_mode)
60 except PowerwallError
as ex:
62 f
"Setting off-grid operation to {island_mode} failed: {ex}"
65 self.
_attr_is_on_attr_is_on = island_mode == IslandMode.OFFGRID
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, PowerwallRuntimeData powerwall_data)
None _async_set_island_mode(self, IslandMode island_mode)
None async_write_ha_state(self)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, PowerwallConfigEntry entry, AddEntitiesCallback async_add_entities)