Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for monitoring juicenet/juicepoint/juicebox based EVSE switches."""
2 
3 from typing import Any
4 
5 from homeassistant.components.switch import SwitchEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from .const import DOMAIN, JUICENET_API, JUICENET_COORDINATOR
11 from .entity import JuiceNetDevice
12 
13 
15  hass: HomeAssistant,
16  config_entry: ConfigEntry,
17  async_add_entities: AddEntitiesCallback,
18 ) -> None:
19  """Set up the JuiceNet switches."""
20  juicenet_data = hass.data[DOMAIN][config_entry.entry_id]
21  api = juicenet_data[JUICENET_API]
22  coordinator = juicenet_data[JUICENET_COORDINATOR]
23 
25  JuiceNetChargeNowSwitch(device, coordinator) for device in api.devices
26  )
27 
28 
30  """Implementation of a JuiceNet switch."""
31 
32  _attr_translation_key = "charge_now"
33 
34  def __init__(self, device, coordinator):
35  """Initialise the switch."""
36  super().__init__(device, "charge_now", coordinator)
37 
38  @property
39  def is_on(self):
40  """Return true if switch is on."""
41  return self.devicedevice.override_time != 0
42 
43  async def async_turn_on(self, **kwargs: Any) -> None:
44  """Charge now."""
45  await self.devicedevice.set_override(True)
46 
47  async def async_turn_off(self, **kwargs: Any) -> None:
48  """Don't charge now."""
49  await self.devicedevice.set_override(False)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:18