-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
from typing import Any, Dict | ||
from .device import Attributes, Device | ||
from ..hub.abstract_smart_home_hub import AbstractSmartHomeHub | ||
|
||
|
||
class WaterSensorAttributes(Attributes): | ||
battery_percentage: int | ||
water_leak_detected: bool | ||
|
||
class WaterSensor(Device): | ||
dirigera_client: AbstractSmartHomeHub | ||
attributes: WaterSensorAttributes | ||
|
||
def reload(self) -> WaterSensor: | ||
data = self.dirigera_client.get(route=f"/devices/{self.id}") | ||
return WaterSensor(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_water_sensor( | ||
data: Dict[str, Any], dirigera_client: AbstractSmartHomeHub | ||
) -> WaterSensor: | ||
return WaterSensor(dirigeraClient=dirigera_client, **data) |