Add Keba charging station/wallbox as component (#24484)
* Add Keba charging station wallbox component * Added start/stop commands (ena 0 and ena 1) * added refresh_interval parameter and fixed authorization * fixed max line length * deactivate failsafe mode if not set in configuration * extracted I/O code to pypi library * updated services.yaml * pinned version of requirements * fixed typos, indent and comments * simplified sensor generation, fixed unique_id and name of sensors * cleaned up data extraction * flake8 fixes * added fast polling, fixed unique_id, code cleanup * updated requirements * fixed pylint * integrated code styling suggestions * fixed pylint * code style changes according to suggestions and pylint fixes * formatted with black * clarefied variables * Update homeassistant/components/keba/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * Update homeassistant/components/keba/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * Update homeassistant/components/keba/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * Update homeassistant/components/keba/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * fixed behaviour if no charging station was found * fix pylint * Update homeassistant/components/keba/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se>
This commit is contained in:
1 parent
15ab004e98
commit
75e18d4282
9 files changed
+586
No files matched your search
@@ -0,0 +1,108 @@
|
||||
"""Support for KEBA charging station binary sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_PLUG,
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_SAFETY,
|
||||
)
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the KEBA charging station platform."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
keba = hass.data[DOMAIN]
|
||||
|
||||
sensors = [
|
||||
KebaBinarySensor(keba, "Online", "Wallbox", DEVICE_CLASS_CONNECTIVITY),
|
||||
KebaBinarySensor(keba, "Plug", "Plug", DEVICE_CLASS_PLUG),
|
||||
KebaBinarySensor(keba, "State", "Charging state", DEVICE_CLASS_POWER),
|
||||
KebaBinarySensor(keba, "Tmo FS", "Failsafe Mode", DEVICE_CLASS_SAFETY),
|
||||
]
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
class KebaBinarySensor(BinarySensorDevice):
|
||||
"""Representation of a binary sensor of a KEBA charging station."""
|
||||
|
||||
def __init__(self, keba, key, sensor_name, device_class):
|
||||
"""Initialize the KEBA Sensor."""
|
||||
self._key = key
|
||||
self._keba = keba
|
||||
self._name = sensor_name
|
||||
self._device_class = device_class
|
||||
self._is_on = None
|
||||
self._attributes = {}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Deactivate polling. Data updated by KebaHandler."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID of the binary sensor."""
|
||||
return f"{self._keba.device_name}_{self._name}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this sensor."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if sensor is on."""
|
||||
return self._is_on
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the binary sensor."""
|
||||
return self._attributes
|
||||
|
||||
async def async_update(self):
|
||||
"""Get latest cached states from the device."""
|
||||
if self._key == "Online":
|
||||
self._is_on = self._keba.get_value(self._key)
|
||||
|
||||
elif self._key == "Plug":
|
||||
self._is_on = self._keba.get_value("Plug_plugged")
|
||||
self._attributes["plugged_on_wallbox"] = self._keba.get_value(
|
||||
"Plug_wallbox"
|
||||
)
|
||||
self._attributes["plug_locked"] = self._keba.get_value("Plug_locked")
|
||||
self._attributes["plugged_on_EV"] = self._keba.get_value("Plug_EV")
|
||||
|
||||
elif self._key == "State":
|
||||
self._is_on = self._keba.get_value("State_on")
|
||||
self._attributes["status"] = self._keba.get_value("State_details")
|
||||
self._attributes["max_charging_rate"] = str(
|
||||
self._keba.get_value("Max curr")
|
||||
)
|
||||
|
||||
elif self._key == "Tmo FS":
|
||||
self._is_on = not self._keba.get_value("FS_on")
|
||||
self._attributes["failsafe_timeout"] = str(self._keba.get_value("Tmo FS"))
|
||||
self._attributes["fallback_current"] = str(self._keba.get_value("Curr FS"))
|
||||
elif self._key == "Authreq":
|
||||
self._is_on = self._keba.get_value(self._key) == 0
|
||||
|
||||
def update_callback(self):
|
||||
"""Schedule a state update."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Add update callback after being added to hass."""
|
||||
self._keba.add_update_listener(self.update_callback)
|
||||
Reference in new issue
Block a user