diff --git a/Protocol.md b/Protocol.md index a2962c3..9101010 100644 --- a/Protocol.md +++ b/Protocol.md @@ -268,3 +268,7 @@ For static content in the mobile app : For device renaming from the mobile App, a server message is sent : {'name': 'device', 'action': 'update', 'data': {'id': 'L4HActuator_....', 'provider': 'L4HActuator', 'name': 'New name for light', 'modelName': 'CWMSwd-2B', 'vendor': 'Chacon', 'hardwareVersion': '1.0', 'softwareVersion': '1.0.6', 'macAddress': '...', 'type': '.dio1.wifi.genericSwitch.switch.', 'roomName': '...', 'roomId': '...', 'image': None, 'isNew': False}} + +For plug setting's to set the blue status light on or off : + + {"method":"POST","path":"/device/L4HActuator_..../action/quietmode","parameters":{"value":1},"id":9} diff --git a/pyproject.toml b/pyproject.toml index ad2cba5..e4a8caa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dio-chacon-wifi-api" -version = "1.0.0" +version = "1.0.1" description = "Python library for DIO Chacon wifi's protocol for shutters and switches" authors = ["cnico"] license = "GNU Lesser General Public License v3 or later (LGPLv3+)" diff --git a/src/dio_chacon_wifi_api/exceptions.py b/src/dio_chacon_wifi_api/exceptions.py index dfc1bdc..d23d4fa 100644 --- a/src/dio_chacon_wifi_api/exceptions.py +++ b/src/dio_chacon_wifi_api/exceptions.py @@ -1,4 +1,4 @@ -"""Exceptions for DIOChaconAPIClient.""" +"""Exceptions for DIOChacon API.""" class DIOChaconAPIError(Exception): @@ -6,3 +6,10 @@ class DIOChaconAPIError(Exception): def __init__(self, *args) -> None: Exception.__init__(self, *args) + + +class DIOChaconInvalidAuthError(Exception): + """Invalid auth detected""" + + def __init__(self, *args) -> None: + Exception.__init__(self, *args) diff --git a/src/dio_chacon_wifi_api/session.py b/src/dio_chacon_wifi_api/session.py index 4627ae5..677b4db 100644 --- a/src/dio_chacon_wifi_api/session.py +++ b/src/dio_chacon_wifi_api/session.py @@ -9,6 +9,8 @@ import aiohttp +from .exceptions import DIOChaconInvalidAuthError + MAX_FAILED_ATTEMPTS = 5 STATE_CONNECTED = "connected" @@ -88,6 +90,11 @@ async def on_request_end(session, trace_config_ctx, params): self._aiohttp_session = aiohttp.ClientSession(trace_configs=[trace_config]) async with self._aiohttp_session.post(url=self._auth_url, data=payload_data, headers=headers_token) as resp: resp_json = await resp.json() + if resp_json["status"] == 400: + err_msg = resp_json["data"] + _LOGGER.debug("Invalid auth response received : %s", err_msg) + await self._aiohttp_session.close() + raise DIOChaconInvalidAuthError(err_msg) self._sessionToken = str(resp_json["data"]["sessionToken"]) _LOGGER.debug("SessionToken of authentication : " + self._sessionToken) diff --git a/tests/test_const.py b/tests/test_const.py index 738193f..6abcb13 100644 --- a/tests/test_const.py +++ b/tests/test_const.py @@ -1,5 +1,5 @@ # coding: utf-8 -"""Tests client.py. DIOChaconAPIClient class.""" +"""Tests consts.""" from dio_chacon_wifi_api.const import DeviceTypeEnum diff --git a/tests/test_exception.py b/tests/test_exception.py new file mode 100644 index 0000000..15eba0c --- /dev/null +++ b/tests/test_exception.py @@ -0,0 +1,14 @@ +# coding: utf-8 +"""Tests exceptions.""" +import pytest +from dio_chacon_wifi_api.exceptions import DIOChaconAPIError +from dio_chacon_wifi_api.exceptions import DIOChaconInvalidAuthError + + +def test_exceptions() -> None: + + with pytest.raises(DIOChaconAPIError): + raise DIOChaconAPIError("Dumb test coverage") + + with pytest.raises(DIOChaconInvalidAuthError): + raise DIOChaconInvalidAuthError("Dumb 2")