fix zero handling
This commit is contained in:
@@ -24,6 +24,10 @@ logger = logging.getLogger(__name__)
|
||||
SENSOR_DEVICE_TYPES = {"WoIOSensor"}
|
||||
|
||||
|
||||
def is_all_zero_reading(status: dict[str, Any]) -> bool:
|
||||
return status.get("temperature") == 0 and status.get("humidity") == 0 and status.get("battery") == 0
|
||||
|
||||
|
||||
def upsert_device(device_data: dict[str, Any]) -> None:
|
||||
device_id = device_data["deviceId"]
|
||||
with session_scope() as session:
|
||||
@@ -55,6 +59,10 @@ def save_reading(device: Device, status: dict[str, Any]) -> None:
|
||||
logger.info("Skipping %s (%s): status has no temperature/humidity", device.name, device.id)
|
||||
return
|
||||
|
||||
if is_all_zero_reading(status):
|
||||
logger.info("Skipping %s (%s): status is all zeros", device.name, device.id)
|
||||
return
|
||||
|
||||
reading = Reading(
|
||||
device_id=device.id,
|
||||
recorded_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
|
||||
Reference in New Issue
Block a user