From afc6cd76f179ba688b195551da9db2b482a11ed0 Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Sat, 9 Dec 2023 16:26:20 +0000 Subject: [PATCH] Distinguish Pura 4 from Pura 3 --- custom_components/pura/entity.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/custom_components/pura/entity.py b/custom_components/pura/entity.py index 373fcf4..9690fa5 100644 --- a/custom_components/pura/entity.py +++ b/custom_components/pura/entity.py @@ -1,6 +1,8 @@ """Pura entities.""" from __future__ import annotations +from typing import Any + from homeassistant.config_entries import ConfigEntry from homeassistant.helpers.device_registry import ( CONNECTION_BLUETOOTH, @@ -16,7 +18,15 @@ UPDATE_INTERVAL = 30 -PURA_MODEL_MAP = {1: "Pura 3", "car": "Pura Car"} +PURA_MODEL_MAP = {1: "Wall", 2: "Car", "car": "Car", 3: "Plus", 4: "Mini"} + + +def determine_pura_model(data: dict[str, Any]) -> str | None: + """Determine pura device model.""" + if (model := PURA_MODEL_MAP.get(m := data.get("model"), m)) == "Wall": + version = data.get("hwVersion", "3").split(".", 1)[0] + model = "3" if version in ("1", "2") else version + return f"Pura {model}" def has_fragrance(data: dict, bay: int) -> bool: @@ -58,7 +68,7 @@ def __init__( }, identifiers={(DOMAIN, device_id)}, manufacturer="Pura", - model=PURA_MODEL_MAP.get(model := device.get("model"), model), + model=determine_pura_model(device), name=f"{name} Diffuser", suggested_area=name if device_type == "wall" else None, sw_version=first_key_value(device, ("fw_version", "fwVersion")),