Skip to content

Commit cb5c101

Browse files
committed
Stop using cached property
1 parent 086bb32 commit cb5c101

5 files changed

Lines changed: 28 additions & 35 deletions

File tree

custom_components/google_nest_fan/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
from typing import cast
77

88
from google_nest_sdm.device import Device
9+
from google_nest_sdm.device_traits import FanTrait
910
from google_nest_sdm.exceptions import ApiException
11+
from google_nest_sdm.thermostat_traits import ThermostatHvacTrait
1012

1113
# pylint: disable=hass-component-root-import
12-
from homeassistant.components.nest import NestConfigEntry
13-
from homeassistant.components.nest.climate import FanTrait, ThermostatHvacTrait
1414
from homeassistant.components.nest.const import DOMAIN as NEST_DOMAIN
15+
from homeassistant.components.nest.types import NestConfigEntry
16+
17+
# pylint: enable=hass-component-root-import
1518
from homeassistant.config_entries import ConfigEntry
1619
from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID
1720
from homeassistant.core import HomeAssistant, ServiceCall
@@ -85,7 +88,9 @@ async def _async_run_fan(call: ServiceCall) -> None:
8588
trait: FanTrait = device.traits[FanTrait.NAME]
8689
try:
8790
if duration.total_seconds() > 0:
88-
await trait.set_timer("ON", duration=round(duration.total_seconds()))
91+
await trait.set_timer(
92+
"ON", duration=round(duration.total_seconds())
93+
)
8994
else:
9095
await trait.set_timer("OFF")
9196
except ApiException as err:
@@ -133,4 +138,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoogleNestFan) -> bool:
133138

134139
async def async_unload_entry(hass: HomeAssistant, entry: GoogleNestFan) -> bool:
135140
"""Unload a config entry."""
136-
return True
141+
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

custom_components/google_nest_fan/config_flow.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
from __future__ import annotations
44

5-
import logging
6-
7-
# from typing import Any
85
from google_nest_sdm.device import Device
6+
from google_nest_sdm.thermostat_traits import ThermostatHvacTrait
97

108
# pylint: disable=hass-component-root-import
11-
from homeassistant.components.nest.climate import ThermostatHvacTrait
129
from homeassistant.components.nest.const import DOMAIN as NEST_DOMAIN
1310
from homeassistant.components.nest.types import NestConfigEntry
1411

15-
# from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
12+
# pylint: enable=hass-component-root-import
1613
from homeassistant.core import HomeAssistant
1714
from homeassistant.helpers import config_entry_flow
1815

1916
from .const import DOMAIN
2017

21-
_LOGGER = logging.getLogger(__name__)
22-
2318

2419
def _async_has_configured_thermostats(hass: HomeAssistant) -> bool:
2520
entries: list[NestConfigEntry] = hass.config_entries.async_loaded_entries(
@@ -43,7 +38,7 @@ def _async_has_configured_thermostats(hass: HomeAssistant) -> bool:
4338

4439

4540
# class GoogleNestFanFlow(ConfigFlow, domain=DOMAIN):
46-
# """Google Nest Fan Flow."""
41+
# """Google Nest Fan Flow.""
4742

4843
# async def async_step_user(
4944
# self, user_input: dict[str, Any] | None = None

custom_components/google_nest_fan/const.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111
DOMAIN = "google_nest_fan"
1212
PLATFORMS = {Platform.SENSOR}
1313

14-
# SCAN_INTERVAL = timedelta(minutes=1)
15-
1614
FAN_SERVICE_DURATION = "duration"
1715

1816
FAN_SERVICE = "run_fan"
1917

2018
MAX_RUN_TIME: Final[timedelta] = timedelta(hours=15)
2119

22-
# RUN_TIME_DEBOUNCE: Final[timedelta] = timedelta(seconds=2)
23-
2420
FAN_SERVICE_SCHEMA = vol.Schema(
2521
vol.All(
2622
{

custom_components/google_nest_fan/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"requirements": [],
1313
"ssdp": [],
1414
"zeroconf": [],
15-
"version": "2025.10.4",
16-
"integration_type": "service",
15+
"version": "2025.11.1",
16+
"integration_type": "helper",
1717
"issue_tracker": "https://github.com/iluvdata/google_nest_fan/issues"
1818
}

custom_components/google_nest_fan/sensor.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from homeassistant.components.nest.device_info import NestDeviceInfo
1111
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
1212
from homeassistant.core import HomeAssistant
13-
from homeassistant.helpers.entity import cached_property
13+
import homeassistant.helpers.device_registry as dr
1414
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
1515

1616
from . import GoogleNestFan
@@ -47,38 +47,35 @@ def __init__(self, hass: HomeAssistant, device: Device) -> None:
4747
"""Initialize the sensor."""
4848
super().__init__()
4949
self._device: Device = device
50-
self._device_info = NestDeviceInfo(device)
50+
self._device_info: NestDeviceInfo = NestDeviceInfo(device)
5151
# The API "name" field is a unique device identifier.
5252
self._attr_unique_id = f"{device.name}-{self.device_class}"
53-
self._attr_device_info = self._device_info.device_info
53+
if "identifiers" in self._device_info.device_info:
54+
self.device_entry = dr.async_get(hass).async_get_device(
55+
self._device_info.device_info["identifiers"]
56+
)
5457

55-
@cached_property
56-
def available(self) -> bool:
58+
@property
59+
def available(self) -> bool: # pyright: ignore[reportIncompatibleVariableOverride]
5760
"""Return device availability."""
58-
return self._device_info.available
59-
60-
async def async_update(self) -> None:
61-
"""Called on init."""
62-
self.async_write_ha_state()
61+
return NestDeviceInfo(self._device).available
6362

6463
async def async_added_to_hass(self) -> None:
6564
"""Run when entity is added to register update signal handler."""
6665
self.async_on_remove(
6766
self._device.add_update_listener(self.async_write_ha_state)
6867
)
69-
await self.async_update()
7068

71-
@cached_property
72-
def native_value(self) -> datetime.datetime | str:
69+
@property
70+
def native_value(self) -> datetime.datetime | None: # pyright: ignore[reportIncompatibleVariableOverride]
7371
"""Return the state of the sensor."""
7472
fan_trait: FanTrait = self._device.traits[FanTrait.NAME]
7573
_LOGGER.debug(
76-
"Updating fan timer timeout: %s, timerMode: %s",
74+
"Updating %s: %s, timerMode: %s",
75+
self.entity_id,
7776
fan_trait.timer_timeout,
7877
fan_trait.timer_mode,
7978
)
8079
if not fan_trait.timer_timeout or fan_trait.timer_mode == "OFF":
81-
self._attr_device_class = None
82-
return "Not Running"
83-
self._attr_device_class = SensorDeviceClass.TIMESTAMP
80+
return None
8481
return fan_trait.timer_timeout

0 commit comments

Comments
 (0)