|
@@ -96,12 +96,6 @@ def current_hour(now: datetime | None = None) -> datetime:
|
|
|
return now.replace(minute=0, second=0, microsecond=0)
|
|
return now.replace(minute=0, second=0, microsecond=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _as_int(value: Any) -> int | None:
|
|
|
|
|
- if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
|
|
|
- return None
|
|
|
|
|
- return int(value)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
def _as_float(value: Any) -> float | None:
|
|
def _as_float(value: Any) -> float | None:
|
|
|
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
|
return None
|
|
return None
|
|
@@ -133,18 +127,12 @@ class HourBucket:
|
|
|
self.hour = hour
|
|
self.hour = hour
|
|
|
self.temps: list[float] = []
|
|
self.temps: list[float] = []
|
|
|
self.hums: list[float] = []
|
|
self.hums: list[float] = []
|
|
|
- self.battery: int | None = None
|
|
|
|
|
- self.linkquality: int | None = None
|
|
|
|
|
|
|
|
|
|
def add(self, payload: dict[str, Any]) -> None:
|
|
def add(self, payload: dict[str, Any]) -> None:
|
|
|
if isinstance(payload.get("temperature"), (int, float)):
|
|
if isinstance(payload.get("temperature"), (int, float)):
|
|
|
self.temps.append(float(payload["temperature"]))
|
|
self.temps.append(float(payload["temperature"]))
|
|
|
if isinstance(payload.get("humidity"), (int, float)):
|
|
if isinstance(payload.get("humidity"), (int, float)):
|
|
|
self.hums.append(float(payload["humidity"]))
|
|
self.hums.append(float(payload["humidity"]))
|
|
|
- if isinstance(payload.get("battery"), (int, float)):
|
|
|
|
|
- self.battery = int(payload["battery"])
|
|
|
|
|
- if isinstance(payload.get("linkquality"), (int, float)):
|
|
|
|
|
- self.linkquality = int(payload["linkquality"])
|
|
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def empty(self) -> bool:
|
|
def empty(self) -> bool:
|
|
@@ -164,8 +152,6 @@ class HourBucket:
|
|
|
"humidity_min": min(self.hums) if self.hums else None,
|
|
"humidity_min": min(self.hums) if self.hums else None,
|
|
|
"humidity_max": max(self.hums) if self.hums else None,
|
|
"humidity_max": max(self.hums) if self.hums else None,
|
|
|
"samples": max(len(self.temps), len(self.hums)),
|
|
"samples": max(len(self.temps), len(self.hums)),
|
|
|
- "battery": self.battery,
|
|
|
|
|
- "linkquality": self.linkquality,
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -189,7 +175,6 @@ class DoorTracker:
|
|
|
if device in self.last and self.last[device] == contact:
|
|
if device in self.last and self.last[device] == contact:
|
|
|
return None
|
|
return None
|
|
|
self.last[device] = contact
|
|
self.last[device] = contact
|
|
|
- battery_low = payload.get("battery_low")
|
|
|
|
|
return {
|
|
return {
|
|
|
"ts": ts.strftime("%Y-%m-%d %H:%M:%S"),
|
|
"ts": ts.strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
"device": device,
|
|
"device": device,
|
|
@@ -197,10 +182,6 @@ class DoorTracker:
|
|
|
# SNZB-04P: contact=true = suletud, false = avatud (Z2M HA discovery
|
|
# SNZB-04P: contact=true = suletud, false = avatud (Z2M HA discovery
|
|
|
# payload_on=false, payload_off=true, device_class=door).
|
|
# payload_on=false, payload_off=true, device_class=door).
|
|
|
"olek": "suletud" if contact else "avatud",
|
|
"olek": "suletud" if contact else "avatud",
|
|
|
- "battery": _as_int(payload.get("battery")),
|
|
|
|
|
- "voltage": _as_int(payload.get("voltage")),
|
|
|
|
|
- "linkquality": _as_int(payload.get("linkquality")),
|
|
|
|
|
- "battery_low": battery_low if isinstance(battery_low, bool) else None,
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|