Skip to content

Commit 5dd4dd3

Browse files
authored
add post connect backstop, fix ssl references (#1530)
1 parent 3aa3b10 commit 5dd4dd3

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

custom_components/ocpp/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
137137

138138
async def async_migrate_entry(hass, config_entry: ConfigEntry):
139139
"""Migrate old entry."""
140-
_LOGGER.debug(
140+
_LOGGER.info(
141141
"Migrating configuration from version %s.%s",
142142
config_entry.version,
143143
config_entry.minor_version,
@@ -182,14 +182,17 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
182182
new_data = csid_data
183183
cp_id = hass.states.get(f"sensor.{cpid_data[CONF_CPID]}_id")
184184
if cp_id is None:
185+
_LOGGER.warning(
186+
"Could not find charger id during migration, try a clean install"
187+
)
185188
return False
186189
new_data.update({CONF_CPIDS: [{cp_id: cpid_data}]})
187190

188191
hass.config_entries.async_update_entry(
189192
config_entry, data=new_data, minor_version=0, version=2
190193
)
191194

192-
_LOGGER.debug(
195+
_LOGGER.info(
193196
"Migration to configuration version %s.%s successful",
194197
config_entry.version,
195198
config_entry.minor_version,

custom_components/ocpp/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ async def create(hass: HomeAssistant, entry: ConfigEntry):
150150
if self.settings.ssl:
151151
self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
152152
# see https://community.home-assistant.io/t/certificate-authority-and-self-signed-certificate-for-ssl-tls/196970
153-
localhost_certfile = self.settings.certfile
154-
localhost_keyfile = self.settings.keyfile
153+
localhost_certfile = self.settings.ssl_certfile_path
154+
localhost_keyfile = self.settings.ssl_keyfile_path
155155
await self.hass.async_add_executor_job(
156156
partial(
157157
self.ssl_context.load_cert_chain,

custom_components/ocpp/chargepoint.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ async def monitor_connection(self):
341341
self._metrics[cstat.latency_pong.value].unit = "ms"
342342
connection = self._connection
343343
timeout_counter = 0
344+
# Add backstop to start post connect for non-compliant chargers
345+
# after 10s to allow for when a boot notification has not been received
346+
await asyncio.sleep(10)
347+
if not self.post_connect_success:
348+
self.hass.async_create_task(self.post_connect())
344349
while connection.state is State.OPEN:
345350
try:
346351
await asyncio.sleep(self.cs_settings.websocket_ping_interval)
@@ -388,6 +393,7 @@ async def _handle_call(self, msg):
388393

389394
async def start(self):
390395
"""Start charge point."""
396+
# post connect now handled on receiving boot notification or with backstop in monitor connection
391397
await self.run([super().start(), self.monitor_connection()])
392398

393399
async def run(self, tasks):
@@ -424,10 +430,8 @@ async def reconnect(self, connection: ServerConnection):
424430
self.status = STATE_OK
425431
self._connection = connection
426432
self._metrics[cstat.reconnects.value].value += 1
427-
if self.post_connect_success is True:
428-
await self.run([super().start(), self.monitor_connection()])
429-
else:
430-
await self.run([super().start(), self.monitor_connection()])
433+
# post connect now handled on receiving boot notification or with backstop in monitor connection
434+
await self.run([super().start(), self.monitor_connection()])
431435

432436
async def async_update_device_info(
433437
self, serial: str, vendor: str, model: str, firmware_version: str
@@ -453,7 +457,8 @@ async def async_update_device_info(
453457
def _register_boot_notification(self):
454458
if self.triggered_boot_notification is False:
455459
self.hass.async_create_task(self.notify_ha(f"Charger {self.id} rebooted"))
456-
self.hass.async_create_task(self.post_connect())
460+
if not self.post_connect_success:
461+
self.hass.async_create_task(self.post_connect())
457462

458463
async def update(self, cpid: str):
459464
"""Update sensors values in HA."""

0 commit comments

Comments
 (0)