forked from Leggin/dirigera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_close_sensor.py
31 lines (22 loc) · 1.06 KB
/
open_close_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations
from typing import Any, Dict
from .device import Attributes, Device
from ..hub.abstract_smart_home_hub import AbstractSmartHomeHub
class OpenCloseSensorAttributes(Attributes):
is_open: bool
class OpenCloseSensor(Device):
dirigera_client: AbstractSmartHomeHub
attributes: OpenCloseSensorAttributes
def reload(self) -> OpenCloseSensor:
data = self.dirigera_client.get(route=f"/devices/{self.id}")
return OpenCloseSensor(dirigeraClient=self.dirigera_client, **data)
def set_name(self, name: str) -> None:
if "customName" not in self.capabilities.can_receive:
raise AssertionError("This sensor does not support the set_name function")
data = [{"attributes": {"customName": name}}]
self.dirigera_client.patch(route=f"/devices/{self.id}", data=data)
self.attributes.custom_name = name
def dict_to_open_close_sensor(
data: Dict[str, Any], dirigera_client: AbstractSmartHomeHub
) -> OpenCloseSensor:
return OpenCloseSensor(dirigeraClient=dirigera_client, **data)