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.
This commit is contained in:
Marc Billow
2026-08-03 00:25:46 +00:00
parent 24d48d70b9
commit 9dc1facbfe
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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