Enable config flow for Tesla (#28744)
* build: bump teslajsonpy to 0.2.0 * Remove tests * feat: add config flow * feat: add async * perf: convert unnecessary async calls to sync * feat: add charger voltage and current sensor * feat: add options flow * build: bump teslajsonpy to 0.2.0 * Remove icon property * Revert climate mode change * Remove charger sensor * Simplify async_setup_platform * Update homeassistant/components/tesla/sensor.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/tesla/binary_sensor.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Address requested changes * Fix pylint error * Address requested changes * Update codeowners * Fix pylint error * Address requested changes * Address requested change * Remove unnecessary check for existing config entry * Load scan_interval in async_setup_entry * Include coverage of config_flow * Add tests for full coverage * Address requested test changes * Remove unnecessary init lines * Remove unnecessary init Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
1 parent
edce497a0d
commit
3aa2ae1700
17 files changed
+671
-122
No files matched your search
@@ -9,26 +9,31 @@ from . import DOMAIN as TESLA_DOMAIN, TeslaDevice
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Tesla switch platform."""
|
||||
controller = hass.data[TESLA_DOMAIN]["controller"]
|
||||
devices = []
|
||||
for device in hass.data[TESLA_DOMAIN]["devices"]["switch"]:
|
||||
pass
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Tesla binary_sensors by config_entry."""
|
||||
controller = hass.data[TESLA_DOMAIN][config_entry.entry_id]["controller"]
|
||||
entities = []
|
||||
for device in hass.data[TESLA_DOMAIN][config_entry.entry_id]["devices"]["switch"]:
|
||||
if device.bin_type == 0x8:
|
||||
devices.append(ChargerSwitch(device, controller))
|
||||
devices.append(UpdateSwitch(device, controller))
|
||||
entities.append(ChargerSwitch(device, controller, config_entry))
|
||||
entities.append(UpdateSwitch(device, controller, config_entry))
|
||||
elif device.bin_type == 0x9:
|
||||
devices.append(RangeSwitch(device, controller))
|
||||
add_entities(devices, True)
|
||||
entities.append(RangeSwitch(device, controller, config_entry))
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class ChargerSwitch(TeslaDevice, SwitchDevice):
|
||||
"""Representation of a Tesla charger switch."""
|
||||
|
||||
def __init__(self, tesla_device, controller):
|
||||
def __init__(self, tesla_device, controller, config_entry):
|
||||
"""Initialise of the switch."""
|
||||
self._state = None
|
||||
super().__init__(tesla_device, controller)
|
||||
super().__init__(tesla_device, controller, config_entry)
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Send the on command."""
|
||||
@@ -55,10 +60,10 @@ class ChargerSwitch(TeslaDevice, SwitchDevice):
|
||||
class RangeSwitch(TeslaDevice, SwitchDevice):
|
||||
"""Representation of a Tesla max range charging switch."""
|
||||
|
||||
def __init__(self, tesla_device, controller):
|
||||
def __init__(self, tesla_device, controller, config_entry):
|
||||
"""Initialise the switch."""
|
||||
self._state = None
|
||||
super().__init__(tesla_device, controller)
|
||||
super().__init__(tesla_device, controller, config_entry)
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Send the on command."""
|
||||
@@ -85,11 +90,11 @@ class RangeSwitch(TeslaDevice, SwitchDevice):
|
||||
class UpdateSwitch(TeslaDevice, SwitchDevice):
|
||||
"""Representation of a Tesla update switch."""
|
||||
|
||||
def __init__(self, tesla_device, controller):
|
||||
def __init__(self, tesla_device, controller, config_entry):
|
||||
"""Initialise the switch."""
|
||||
self._state = None
|
||||
tesla_device.type = "update switch"
|
||||
super().__init__(tesla_device, controller)
|
||||
super().__init__(tesla_device, controller, config_entry)
|
||||
self._name = self._name.replace("charger", "update")
|
||||
self.tesla_id = self.tesla_id.replace("charger", "update")
|
||||
|
||||
|
||||
Reference in new issue
Block a user