* Add config flow to JuiceNet * Fix some lint issues * Fix imports * Abort on reconfigure / Allow multiple accounts Abort on bad API token Fix strings * Remove unused variable * Update strings * Remove import * Fix import order again * Update imports Remove some unused parameters * Add back ignore * Update config_flow.py * iSort * Update juicenet integration to be async * Update coverage for juicenet config flow * Update homeassistant/components/juicenet/entity.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Black * Make imports relative * Rename translations folder Co-authored-by: J. Nick Koston <nick@koston.org>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Support for monitoring juicenet/juicepoint/juicebox based EVSE switches."""
|
|
import logging
|
|
|
|
from homeassistant.components.switch import SwitchEntity
|
|
|
|
from .const import DOMAIN, JUICENET_API, JUICENET_COORDINATOR
|
|
from .entity import JuiceNetDevice
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
"""Set up the JuiceNet switches."""
|
|
entities = []
|
|
juicenet_data = hass.data[DOMAIN][config_entry.entry_id]
|
|
api = juicenet_data[JUICENET_API]
|
|
coordinator = juicenet_data[JUICENET_COORDINATOR]
|
|
|
|
for device in api.devices:
|
|
entities.append(JuiceNetChargeNowSwitch(device, coordinator))
|
|
async_add_entities(entities)
|
|
|
|
|
|
class JuiceNetChargeNowSwitch(JuiceNetDevice, SwitchEntity):
|
|
"""Implementation of a JuiceNet switch."""
|
|
|
|
def __init__(self, device, coordinator):
|
|
"""Initialise the switch."""
|
|
super().__init__(device, "charge_now", coordinator)
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the device."""
|
|
return f"{self.device.name} Charge Now"
|
|
|
|
@property
|
|
def is_on(self):
|
|
"""Return true if switch is on."""
|
|
return self.device.override_time != 0
|
|
|
|
async def async_turn_on(self, **kwargs):
|
|
"""Charge now."""
|
|
await self.device.set_override(True)
|
|
|
|
async def async_turn_off(self, **kwargs):
|
|
"""Don't charge now."""
|
|
await self.device.set_override(False)
|