Skip to content

Commit

Permalink
Added auto local re-authentication after power loss with the default …
Browse files Browse the repository at this point in the history
…password.
  • Loading branch information
slydiman committed Dec 2, 2024
1 parent 9d784db commit e841712
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
27 changes: 25 additions & 2 deletions custom_components/sscpoe/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
import async_timeout
from datetime import timedelta
from .const import DOMAIN, LOGGER
from .protocol import SSCPOE_CLOUD_KEY, SSCPOE_cloud_request, SSCPOE_local_request
from .protocol import (
SSCPOE_CLOUD_KEY,
SSCPOE_LOCAL_DEF_PASSWORD,
SSCPOE_cloud_request,
SSCPOE_local_request,
SSCPOE_local_login,
)


class SSCPOE_Coordinator(DataUpdateCoordinator):
Expand Down Expand Up @@ -62,7 +68,24 @@ def _fetch_data(self) -> None:
if j is None:
raise ApiError(f"SSCPOE_local_request(detail, {self._sn}): timeout")
if isinstance(j, str):
raise ApiAuthError(j)
LOGGER.debug(
f"SSCPOE_Coordinator._fetch_data: login/activate with the default passowrd."
)
if (
SSCPOE_local_login(self._sn, SSCPOE_LOCAL_DEF_PASSWORD) in None
or SSCPOE_local_login(
self._sn, SSCPOE_LOCAL_DEF_PASSWORD, "activate"
)
in None
):
# Second try after login/activate.
j, err = SSCPOE_local_request({"callcmd": "detail", "sn": self._sn})
if j is None:
raise ApiError(
f"SSCPOE_local_request(detail, {self._sn}): timeout"
)
if isinstance(j, str):
raise ApiAuthError(j)
if err != 0:
raise ApiError(
f"SSCPOE_local_request(detail, {self._sn}) errcode={err}"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sscpoe/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/slydiman/sscpoe/issues",
"requirements": ["requests"],
"version": "2024.11.11",
"version": "2024.12.02",
"zeroconf": []
}
3 changes: 3 additions & 0 deletions custom_components/sscpoe/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ def SSCPOE_local_request(dt):
return d, err


SSCPOE_LOCAL_DEF_PASSWORD = "123456"


def SSCPOE_local_login(sn: str, password: str, cmd="login"):
j, err = SSCPOE_local_request(
{
Expand Down

0 comments on commit e841712

Please sign in to comment.