hass-core/homeassistant/components/keba/lock.py
Philipp Danner 70f8bfbd4f Update Integration of Keba charging station (#30125)
* fixed parsing of current to float in service set_current

* Added optional name in the config file in order to get a better entety naming (easier to find)

* fix parsing of all parameters to service calls

* addressed code review comments + updated pypi dependency

* config name imported from cont.py + minor naming changes to be more clear about the meaning of a sensor

* removed name in config again, use product name gathered from the charging station instead

* implemented suggested changes

* changed variable naming as requested
2019-12-22 19:46:53 +01:00

70 lines
1.9 KiB
Python

"""Support for KEBA charging station switch."""
import logging
from homeassistant.components.lock import LockDevice
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 = [KebaLock(keba, "Authentication", "authentication")]
async_add_entities(sensors)
class KebaLock(LockDevice):
"""The entity class for KEBA charging stations switch."""
def __init__(self, keba, name, entity_type):
"""Initialize the KEBA switch."""
self._keba = keba
self._name = name
self._entity_type = entity_type
self._state = True
@property
def should_poll(self):
"""Deactivate polling. Data updated by KebaHandler."""
return False
@property
def unique_id(self):
"""Return the unique ID of the lock."""
return f"{self._keba.device_id}_{self._entity_type}"
@property
def name(self):
"""Return the name of the device."""
return f"{self._keba.device_name} {self._name}"
@property
def is_locked(self):
"""Return true if lock is locked."""
return self._state
async def async_lock(self, **kwargs):
"""Lock wallbox."""
await self._keba.async_stop()
async def async_unlock(self, **kwargs):
"""Unlock wallbox."""
await self._keba.async_start()
async def async_update(self):
"""Attempt to retrieve on off state from the switch."""
self._state = self._keba.get_value("Authreq") == 1
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)