Finished matrix clock client
This commit is contained in:
parent
0330e49ec0
commit
2b17367313
1 changed files with 42 additions and 2 deletions
|
@ -1,8 +1,48 @@
|
|||
from mash.entities.entity import Entity
|
||||
import requests as r
|
||||
|
||||
|
||||
class MatrixClockEntity(Entity):
|
||||
def __init__(self, *, id: str, name: str, room: str, device_type: str, groups: list[str] = ...) -> None:
|
||||
super().__init__(id=id, name=name, room=room, device_type=device_type, groups=groups)
|
||||
|
||||
def __init__(self, *, id: str, name: str, room: str, ip: str, port: int) -> None:
|
||||
super().__init__(id=id, name=name, room=room, device_type="matrixclock")
|
||||
self._ip = ip
|
||||
self._port = port
|
||||
self._base_path = ""
|
||||
|
||||
def __post_request__(self, endpoint: str, content: dict = {}) -> r.Response:
|
||||
url: str = f"http://{self._ip}:{self._port}{self._base_path}/{endpoint}"
|
||||
return r.post(url=url, json=content)
|
||||
|
||||
def display_off(self):
|
||||
self.__post_request__("off")
|
||||
|
||||
def display_time(self):
|
||||
self.__post_request__("time")
|
||||
|
||||
def display_full(self):
|
||||
self.__post_request__("full")
|
||||
|
||||
def display_pattern(self, *, pattern: str = "01", step_ms: int = 500):
|
||||
self.__post_request__(f"pattern?pattern={pattern}&step_ms={step_ms}")
|
||||
|
||||
def get_climate_and_show_temperature(self) -> dict[str, float]:
|
||||
return self.__post_request__("temperature").json()
|
||||
|
||||
def get_climate_and_show_humidity(self) -> dict[str, float]:
|
||||
return self.__post_request__("humidity").json()
|
||||
|
||||
def flash_display(self, *, count: int = 1, contrast: int = None):
|
||||
path = f"flash?count={count}"
|
||||
if contrast:
|
||||
path += "&contrast={contrast}"
|
||||
self.__post_request__(path)
|
||||
|
||||
def set_contrast(self, *, contrast: int):
|
||||
self.__post_request__(f"contrast?contrast={contrast}")
|
||||
|
||||
def get_contrast(self) -> int:
|
||||
return self.__post_request__("contrast").json()["contrast"]
|
||||
|
||||
def show_message(self, *, message: str):
|
||||
self.__post_request__("message", {"message": message})
|
||||
|
|
Loading…
Reference in a new issue