Skip to content

Commit

Permalink
Merge pull request #318 from PeteRager/connection-state-fix
Browse files Browse the repository at this point in the history
state names are only a-z 0-9
  • Loading branch information
PeteRager authored Mar 5, 2024
2 parents 4d15adf + ce6800d commit 333c6cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions custom_components/lennoxs30/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import asyncio
from asyncio.locks import Event
import logging
import re
import time
import voluptuous as vol

Expand Down Expand Up @@ -471,10 +472,10 @@ def __init__(
else:
if ip_address is None:
e_name = email.split("@")
redacted_email: str = e_name[0].replace(".", "_").replace("__","_")
redacted_email: str = re.sub("[^A-Za-z0-9]","",e_name[0])
self.connection_state = "lennoxs30.conn_" + redacted_email
else:
self.connection_state = "lennoxs30.conn_" + self._ip_address.replace(".", "_").replace(":", "_")
self.connection_state = "lennoxs30.conn_" + re.sub("[^A-Za-z0-9]","",self._ip_address)

async def async_shutdown(self, event: Event) -> None:
"""Called when hass shutsdown"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_async_setup_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ async def test_async_setup_entry_multiple(hass, caplog):
assert manager.create_equipment_parameters is False
assert manager._conf_init_wait_time == 30
assert manager.is_metric is True
assert manager.connection_state == "lennoxs30.conn_192_168_1_94"
assert manager.connection_state == "lennoxs30.conn_192168194"

data = {
"cloud_connection": True,
"email": "pete[email protected]",
"email": "_pete[email protected]",
"password": "rage",
"app_id": "homeassistant",
"create_sensors": True,
Expand Down Expand Up @@ -354,7 +354,7 @@ async def test_async_setup_entry_multiple(hass, caplog):
assert manager._poll_interval == 1
assert manager._fast_poll_interval == 0.75
assert manager._fast_poll_count == 5
assert manager.api._username == "pete[email protected]"
assert manager.api._username == "_pete[email protected]"
assert manager.api._password == "rage"
assert manager._pii_message_log is False
assert manager._message_debug_logging is True
Expand All @@ -367,7 +367,7 @@ async def test_async_setup_entry_multiple(hass, caplog):
assert manager.create_equipment_parameters is False
assert manager._conf_init_wait_time == 30
assert manager.is_metric is True
assert manager.connection_state == "lennoxs30.conn_pete_rage"
assert manager.connection_state == "lennoxs30.conn_peterage"


@pytest.mark.asyncio
Expand Down

0 comments on commit 333c6cd

Please sign in to comment.