Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure version entity name is valid #39

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions presence-detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def _do_full_sync(self, away_only=False):

def _update_version_entity(self):
"""Create a script version entity in home assistant"""
ap_name = self._settings.ap_name if self._settings.ap_name else "openwrt_router"
ap_name = (
self._settings.ap_name.replace("-", "_").lower()
if self._settings.ap_name
else "openwrt_router"
)
entity_id = f"{ap_name}.presence_detector_version"

response, ok = self._post(
Expand All @@ -219,7 +223,9 @@ def _update_version_entity(self):
headers={"Authorization": f"Bearer {self._settings.hass_token}"},
)
if not ok:
self._logger.log(f"Unable to create/update version entity in HA: {response}")
self._logger.log(
f"Unable to create/update version entity in HA: {response}"
)

def run(self) -> None:
"""Main loop for the presence detector"""
Expand Down Expand Up @@ -272,10 +278,10 @@ class UbusWatcher(Thread):
"""Watches live ubus events and signals presence detector of leave/join events"""

def __init__(
self,
interface: str,
on_join: Callable[[str], None],
on_leave: Callable[[str], None],
self,
interface: str,
on_join: Callable[[str], None],
on_leave: Callable[[str], None],
) -> None:
super().__init__()
self._on_join = on_join
Expand Down