1 """Support for KEBA charging stations."""
6 from keba_kecontact.connection
import KebaKeContact
7 import voluptuous
as vol
15 _LOGGER = logging.getLogger(__name__)
18 PLATFORMS = (Platform.BINARY_SENSOR, Platform.SENSOR, Platform.LOCK, Platform.NOTIFY)
22 CONF_FS_TIMEOUT =
"failsafe_timeout"
23 CONF_FS_FALLBACK =
"failsafe_fallback"
24 CONF_FS_PERSIST =
"failsafe_persist"
25 CONF_FS_INTERVAL =
"refresh_interval"
27 MAX_POLLING_INTERVAL = 5
28 MAX_FAST_POLLING_COUNT = 4
30 CONFIG_SCHEMA = vol.Schema(
34 vol.Required(CONF_HOST): cv.string,
35 vol.Optional(CONF_RFID, default=
"00845500"): cv.string,
36 vol.Optional(CONF_FS, default=
False): cv.boolean,
37 vol.Optional(CONF_FS_TIMEOUT, default=30): cv.positive_int,
38 vol.Optional(CONF_FS_FALLBACK, default=6): cv.positive_int,
39 vol.Optional(CONF_FS_PERSIST, default=0): cv.positive_int,
40 vol.Optional(CONF_FS_INTERVAL, default=5): cv.positive_int,
44 extra=vol.ALLOW_EXTRA,
48 "request_data":
"async_request_data",
49 "set_energy":
"async_set_energy",
50 "set_current":
"async_set_current",
51 "authorize":
"async_start",
52 "deauthorize":
"async_stop",
53 "enable":
"async_enable_ev",
54 "disable":
"async_disable_ev",
55 "set_failsafe":
"async_set_failsafe",
59 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
60 """Check connectivity and version of KEBA charging station."""
61 host = config[DOMAIN][CONF_HOST]
62 rfid = config[DOMAIN][CONF_RFID]
63 refresh_interval = config[DOMAIN][CONF_FS_INTERVAL]
64 keba =
KebaHandler(hass, host, rfid, refresh_interval)
65 hass.data[DOMAIN] = keba
68 if not await keba.setup():
69 _LOGGER.error(
"Could not find a charging station at %s", host)
73 failsafe = config[DOMAIN][CONF_FS]
74 timeout = config[DOMAIN][CONF_FS_TIMEOUT]
if failsafe
else 0
75 fallback = config[DOMAIN][CONF_FS_FALLBACK]
if failsafe
else 0
76 persist = config[DOMAIN][CONF_FS_PERSIST]
if failsafe
else 0
78 hass.loop.create_task(keba.set_failsafe(timeout, fallback, persist))
79 except ValueError
as ex:
80 _LOGGER.warning(
"Could not set failsafe mode %s", ex)
84 """Execute a service to KEBA charging station.
86 This must be a member function as we need access to the keba
89 function_name = _SERVICE_MAP[call.service]
90 function_call = getattr(keba, function_name)
91 await function_call(call.data)
93 for service
in _SERVICE_MAP:
94 hass.services.async_register(DOMAIN, service, execute_service)
97 for platform
in PLATFORMS:
98 hass.async_create_task(
99 discovery.async_load_platform(hass, platform, DOMAIN, {}, config)
103 keba.start_periodic_request()
109 """Representation of a KEBA charging station connection."""
111 def __init__(self, hass, host, rfid, refresh_interval):
112 """Initialize charging station connection."""
127 """Start periodic data polling."""
131 """Send periodic update requests."""
132 await self.request_data()
136 _LOGGER.debug(
"Periodic data request executed, now wait for 2 seconds")
137 await asyncio.sleep(2)
140 "Periodic data request executed, now wait for %s seconds",
145 _LOGGER.debug(
"Periodic data request rescheduled")
149 """Initialize KebaHandler object."""
150 await super().
setup(loop)
153 await self.request_data()
155 self.get_value(
"Serial")
is not None
156 and self.get_value(
"Product")
is not None
158 self.
device_iddevice_id = f
"keba_wallbox_{self.get_value('Serial')}"
159 self.
device_namedevice_name = self.get_value(
"Product")
165 """Handle component notification via callback."""
171 _LOGGER.debug(
"Notifying %d listeners", len(self.
_update_listeners_update_listeners))
174 _LOGGER.debug(
"Fast polling enabled")
180 """Add a listener for update notifications."""
187 """Request new data in async way."""
188 await self.request_data()
189 _LOGGER.debug(
"New data from KEBA wallbox requested")
192 """Set energy target in async way."""
194 energy = param[
"energy"]
195 await self.set_energy(
float(energy))
197 except (KeyError, ValueError)
as ex:
198 _LOGGER.warning(
"Energy value is not correct. %s", ex)
201 """Set current maximum in async way."""
203 current = param[
"current"]
204 await self.set_current(
float(current))
206 except (KeyError, ValueError)
as ex:
207 _LOGGER.warning(
"Current value is not correct. %s", ex)
210 """Authorize EV in async way."""
211 await self.start(self.
rfidrfid)
215 """De-authorize EV in async way."""
216 await self.stop(self.
rfidrfid)
220 """Enable EV in async way."""
221 await self.enable(
True)
225 """Disable EV in async way."""
226 await self.enable(
False)
230 """Set failsafe mode in async way."""
232 timeout = param[CONF_FS_TIMEOUT]
233 fallback = param[CONF_FS_FALLBACK]
234 persist = param[CONF_FS_PERSIST]
235 await self.set_failsafe(
int(timeout),
float(fallback), bool(persist))
237 except (KeyError, ValueError)
as ex:
240 "Values are not correct for: failsafe_timeout, failsafe_fallback"
241 " and/or failsafe_persist: %s"
def async_enable_ev(self, param=None)
def setup(self, loop=None)
def async_set_failsafe(self, param=None)
def add_update_listener(self, listener)
def async_request_data(self, param)
def async_stop(self, param=None)
def async_set_current(self, param)
def async_start(self, param=None)
def start_periodic_request(self)
def __init__(self, hass, host, rfid, refresh_interval)
def async_set_energy(self, param)
def hass_callback(self, data)
def _periodic_request(self)
def _set_fast_polling(self)
def async_disable_ev(self, param=None)
None execute_service(RuntimeEntryData entry_data, UserService service, ServiceCall call)
bool async_setup(HomeAssistant hass, ConfigType config)