From 9dc1facbfea979202bf4ea12333a341eb952b27f Mon Sep 17 00:00:00 2001 From: Marc Billow Date: Mon, 3 Aug 2026 00:25:46 +0000 Subject: [PATCH] Fix ty diagnostics from newer homeassistant/cryptography type stubs requirements-dev.txt intentionally leaves homeassistant/cryptography unpinned (always test against latest), so ty's view of their stubs can drift between runs. SensorEntity._attr_state_class now requires SensorStateClass rather than a bare str (same fix already applied to _attr_device_class); NameAttribute.value is generic over str | bytes, so narrow it before handing it to re.search. --- custom_components/localthings/config_flow.py | 2 +- custom_components/localthings/sensor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/localthings/config_flow.py b/custom_components/localthings/config_flow.py index fa986cd..8b0e097 100644 --- a/custom_components/localthings/config_flow.py +++ b/custom_components/localthings/config_flow.py @@ -91,7 +91,7 @@ def _fetch_samsung_uuid() -> str: raise RuntimeError(f"No certificate received from {_SAMSUNG_CLOUD_HOST}") cert = _x509.load_der_x509_certificate(der) for attr in cert.subject: - if attr.oid == _x509.oid.NameOID.ORGANIZATIONAL_UNIT_NAME: + if attr.oid == _x509.oid.NameOID.ORGANIZATIONAL_UNIT_NAME and isinstance(attr.value, str): m = re.search(r"uuid:([0-9a-f-]+)", attr.value, re.IGNORECASE) if m: return m.group(1) diff --git a/custom_components/localthings/sensor.py b/custom_components/localthings/sensor.py index 4d98c33..eccbb3e 100644 --- a/custom_components/localthings/sensor.py +++ b/custom_components/localthings/sensor.py @@ -5,7 +5,7 @@ from __future__ import annotations from datetime import timedelta from typing import cast -from homeassistant.components.sensor import SensorDeviceClass, SensorEntity +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, SensorStateClass from homeassistant.config_entries import ConfigEntry from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant @@ -47,7 +47,7 @@ class LocalThingsSensor(LocalThingsEntity, SensorEntity): self._attr_device_class = ( SensorDeviceClass(desc.device_class) if desc.device_class else None ) - self._attr_state_class = desc.state_class + self._attr_state_class = SensorStateClass(desc.state_class) if desc.state_class else None if desc.options: self._attr_options = list(desc.options) self._hysteresis_value = None