Skip to content

Commit addcba0

Browse files
committed
feat(rest): add device configuration endpoints
1 parent 0430b1d commit addcba0

18 files changed

Lines changed: 14562 additions & 120 deletions

dingz/rest/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
from ._client import RestClient
44
from ._types import (
5+
ButtonConfig,
6+
ButtonsConfig,
7+
ConfigDump,
8+
ConfigState,
59
Date,
610
Device,
711
DynLightState,
12+
InputConfig,
13+
InputsConfig,
814
LedState,
915
LightState,
1016
NetworkInfo,
@@ -18,9 +24,15 @@
1824
)
1925

2026
__all__ = [
27+
"ButtonConfig",
28+
"ButtonsConfig",
29+
"ConfigDump",
30+
"ConfigState",
2131
"Date",
2232
"Device",
2333
"DynLightState",
34+
"InputConfig",
35+
"InputsConfig",
2436
"LedState",
2537
"LightState",
2638
"NetworkInfo",

dingz/rest/_client.py

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@
1111
if TYPE_CHECKING:
1212
from types import TracebackType
1313

14-
from ._types import Device, NetworkInfo, Ram, State
14+
from ._types import (
15+
ActionsConfig,
16+
ButtonsConfig,
17+
ConfigDump,
18+
DdiConfig,
19+
Device,
20+
InputsConfig,
21+
LuxConfig,
22+
NetworkInfo,
23+
OutputsConfig,
24+
PirsConfig,
25+
Ram,
26+
ServicesConfig,
27+
State,
28+
SystemConfig,
29+
)
1530

1631

1732
class RestClient:
@@ -78,15 +93,21 @@ async def close(self) -> None:
7893
if self._session_owner:
7994
await self._session.close()
8095

81-
async def _request(self, method: Literal["GET"], endpoint: URL) -> Any: # noqa: ANN401 The return value really could be anything!
96+
async def _request(
97+
self,
98+
method: Literal["GET"],
99+
endpoint: URL,
100+
*,
101+
ignore_content_type: bool = False,
102+
) -> Any: # noqa: ANN401 The return value really could be anything!
82103
async with self._session.request(
83104
method,
84105
self._base_url.join(endpoint),
85106
headers=self._headers,
86107
timeout=self._timeout,
87108
) as resp:
88109
resp.raise_for_status()
89-
return await resp.json()
110+
return await resp.json(content_type=None if ignore_content_type else CONTENT_TYPE_JSON)
90111

91112
async def get_firmware_version(self) -> str:
92113
"""Get the firmware version of the dingz device.
@@ -134,6 +155,47 @@ async def get_network_info(self) -> NetworkInfo:
134155
"""Get general network settings."""
135156
return await self._request("GET", URL("/api/v1/info"))
136157

158+
async def get_button_config(self) -> ButtonsConfig:
159+
"""Get the button configuration."""
160+
return await self._request("GET", URL("/api/v1/button_config"))
161+
162+
async def get_input_config(self) -> InputsConfig:
163+
"""Get the input configuration."""
164+
return await self._request("GET", URL("/api/v1/input_config"))
165+
166+
async def get_pir_config(self) -> PirsConfig:
167+
"""Get the PIR configuration."""
168+
return await self._request("GET", URL("/api/v1/pir_config"))
169+
170+
async def get_lux_config(self) -> LuxConfig:
171+
"""Get the Lux configuration."""
172+
return await self._request("GET", URL("/api/v1/lux_config"))
173+
174+
async def get_output_config(self) -> OutputsConfig:
175+
"""Get the output configuration."""
176+
return await self._request("GET", URL("/api/v1/output_config"))
177+
178+
async def get_services_config(self) -> ServicesConfig:
179+
"""Get the services configuration."""
180+
return await self._request("GET", URL("/api/v1/services_config"))
181+
182+
async def get_system_config(self) -> SystemConfig:
183+
"""Get the system configuration."""
184+
return await self._request("GET", URL("/api/v1/system_config"))
185+
186+
async def get_ddi_config(self) -> DdiConfig:
187+
"""Get the DDI configuration."""
188+
return await self._request("GET", URL("/api/v1/ddi_config"))
189+
190+
async def get_actions_config(self) -> ActionsConfig:
191+
"""Get the actions configuration."""
192+
return await self._request("GET", URL("/api/v1/actions"))
193+
194+
async def get_config_dump(self) -> ConfigDump:
195+
"""Get the full configuration dump."""
196+
# dump_config reports content type application/octet-stream for some reason
197+
return await self._request("GET", URL("/api/v1/dump_config"), ignore_content_type=True)
198+
137199
async def get_state(self) -> State:
138200
"""Get the full dingz status.
139201

dingz/rest/_types/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .config import * # noqa: F403
2+
from .device import * # noqa: F403
3+
from .helpers import * # noqa: F403
4+
from .state import * # noqa: F403

0 commit comments

Comments
 (0)