Skip to content

Commit

Permalink
Create water_sensor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjoyg authored Apr 17, 2024
1 parent b23c6a1 commit f7a0ee6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/dirigera/devices/water_sensor.py
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)

0 comments on commit f7a0ee6

Please sign in to comment.