Skip to content

Commit

Permalink
Remove cached_property decorator - fixes #84
Browse files Browse the repository at this point in the history
  • Loading branch information
h4de5 committed Oct 20, 2024
1 parent d6726c2 commit da37865
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 67 deletions.
25 changes: 12 additions & 13 deletions custom_components/vimar/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Platform for climate integration."""

from functools import cached_property
import logging

from homeassistant.components.climate import ClimateEntity
Expand Down Expand Up @@ -113,7 +112,7 @@ def is_on(self):
self.get_state("funzionamento") == self.get_const_value(VIMAR_CLIMATE_OFF)
]

@cached_property
@property
def supported_features(self):
"""Flag supported features. The device supports a target temperature."""
flags = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
Expand All @@ -123,31 +122,31 @@ def supported_features(self):
flags |= ClimateEntityFeature.AUX_HEAT
return flags

@cached_property
@property
def current_temperature(self):
"""Return current temperature."""
if self.has_state("temperatura"):
return float(self.get_state("temperatura") or 0)
if self.has_state("temperatura_misurata"):
return float(self.get_state("temperatura_misurata") or 0)

@cached_property
@property
def current_humidity(self):
"""Return current humidity."""
if self.has_state("umidita"):
return float(self.get_state("umidita") or 0)

@cached_property
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return float(self.get_state("setpoint") or 0)

@cached_property
@property
def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 0.1

@cached_property
@property
def temperature_unit(self):
"""Return unit of temperature measurement for the system (UnitOfTemperature.CELSIUS or UnitOfTemperature.FAHRENHEIT)."""
# TODO - find a way to handle different units from vimar device
Expand All @@ -158,7 +157,7 @@ def temperature_unit(self):
else:
return UnitOfTemperature.CELSIUS

@cached_property
@property
def hvac_mode(self):
"""Return target operation (e.g.heat, cool, auto, off). Used to determine state."""
# can be HVACMode.HEAT, HVACMode.COOL, HVACMode.OFF
Expand Down Expand Up @@ -195,13 +194,13 @@ def hvac_mode(self):
# else:
# return HVACMode.OFF

@cached_property
@property
def hvac_modes(self):
"""List of available operation modes. See below."""
# button for auto is still there, to clear manual mode, but will not change highlighted icon
return [HVACMode.HEAT, HVACMode.COOL, HVACMode.OFF, HVACMode.AUTO]

@cached_property
@property
def hvac_action(self):
"""Return current HVAC action (heating, cooling, idle, off)."""
# HVACAction.HEATING, HVACAction.COOLING, HVACAction.OFF, HVACAction.IDLE
Expand Down Expand Up @@ -233,18 +232,18 @@ def hvac_action(self):
else:
return HVACAction.IDLE

@cached_property
@property
def is_aux_heat(self):
"""Return True if an auxiliary heater is on. Requires ClimateEntityFeature.AUX_HEAT."""
if self.has_state("stato_boost on/off"):
return self.get_state("stato_boost on/off") != "0"

@cached_property
@property
def fan_modes(self) -> list[str] | None:
"""Return the list of available fan modes. Requires ClimateEntityFeature.FAN_MODE."""
return [FAN_ON, FAN_OFF, FAN_LOW, FAN_MEDIUM, FAN_HIGH]

@cached_property
@property
def fan_mode(self):
"""Return the current fan mode. Requires ClimateEntityFeature.FAN_MODE."""
if self.has_state("modalita_fancoil"):
Expand Down
13 changes: 6 additions & 7 deletions custom_components/vimar/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .vimar_entity import VimarEntity, vimar_setup_entry
from homeassistant.components.cover import CoverEntity
from .const import DEVICE_TYPE_COVERS as CURR_PLATFORM
from functools import cached_property

_LOGGER = logging.getLogger(__name__)

Expand All @@ -27,7 +26,7 @@ class VimarCover(VimarEntity, CoverEntity):
# see:
# https://developers.home-assistant.io/docs/entity_index/#generic-properties
# Return True if the state is based on our assumption instead of reading it from the device. this will ignore is_closed state
@cached_property
@property
def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
return True
Expand All @@ -46,7 +45,7 @@ def __init__(self, coordinator, device_id: int):
def entity_platform(self):
return CURR_PLATFORM

@cached_property
@property
def is_closed(self) -> bool | None:
"""Return if the cover is closed."""
# if _state (stopped) is 1, than stopped was pressed, therefor it cannot be completely closed
Expand All @@ -62,7 +61,7 @@ def is_closed(self) -> bool | None:
else:
return None

@cached_property
@property
def current_cover_position(self):
"""Return current position of cover.
Expand All @@ -73,7 +72,7 @@ def current_cover_position(self):
else:
return None

@cached_property
@property
def current_cover_tilt_position(self):
"""
Return current position of cover tilt.
Expand All @@ -85,12 +84,12 @@ def current_cover_tilt_position(self):
else:
return None

@cached_property
@property
def is_default_state(self):
"""Return True of in default state - resulting in default icon."""
return (self.is_closed, True)[self.is_closed is None]

@cached_property
@property
def supported_features(self) -> CoverEntityFeature:
"""Flag supported features."""
flags = (
Expand Down
23 changes: 13 additions & 10 deletions custom_components/vimar/light.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Platform for light integration."""

from functools import cached_property
import logging
from typing import Any

Expand Down Expand Up @@ -38,32 +37,36 @@ def __init__(self, coordinator, device_id: int):
def entity_platform(self):
return CURR_PLATFORM

@cached_property
def is_on(self):
@property
def is_on(self) -> bool:
"""Set to True if the device is on."""
return self.get_state("on/off") == "1"

@cached_property
@property
def is_default_state(self):
"""Return True of in default state - resulting in default icon."""
return self.is_on

@cached_property
@property
def brightness(self):
"""Return Brightness of this light between 0..255."""
return self.recalculate_brightness(int(self.get_state("value") or 0))

@cached_property
@property
def rgb_color(self) -> tuple[int, int, int] | None:
"""Return RGB colors."""
return (self.get_state("red") or 0, self.get_state("green") or 0, self.get_state("blue") or 0)
return (
self.get_state("red") or 0,
self.get_state("green") or 0,
self.get_state("blue") or 0,
)

@cached_property
@property
def hs_color(self):
"""Return the hue and saturation."""
return color_util.color_RGB_to_hs(*self.rgb_color)

@cached_property
@property
def color_mode(self) -> ColorMode:
"""Return the color mode of the light."""
if self.has_state("red") and self.has_state("green") and self.has_state("blue"):
Expand All @@ -72,7 +75,7 @@ def color_mode(self) -> ColorMode:
return ColorMode.BRIGHTNESS
return ColorMode.ONOFF

@cached_property
@property
def supported_color_modes(self) -> set[ColorMode] | None:
"""Flag supported color modes."""
flags: set[ColorMode] = set()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vimar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://github.com/h4de5/home-assistant-vimar",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/h4de5/home-assistant-vimar/issues",
"version": "2024.10.0"
"version": "2024.10.1"
}
36 changes: 18 additions & 18 deletions custom_components/vimar/vimar_entity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Insteon base entity."""

from functools import cached_property
import logging
from typing import Dict

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
Expand All @@ -18,15 +18,15 @@
_LOGGER,
)
from .vimar_coordinator import VimarDataUpdateCoordinator
from .vimarlink.vimarlink import VimarLink, VimarProject
from .vimarlink.vimarlink import VimarDevice, VimarLink, VimarProject


class VimarEntity(CoordinatorEntity):
"""Vimar abstract base entity."""

_logger = _LOGGER
_logger_is_debug = False
_device = []
_device: VimarDevice | None = None
_device_id = 0
_vimarconnection: VimarLink | None = None
_vimarproject: VimarProject | None = None
Expand All @@ -44,7 +44,7 @@ def __init__(self, coordinator: VimarDataUpdateCoordinator, device_id: int):
self._vimarproject = coordinator.vimarproject
self._reset_status()

if self._device_id in self._vimarproject.devices:
if self._vimarproject is not None and self._device_id in self._vimarproject.devices:
self._device = self._vimarproject.devices[self._device_id]
self._logger = logging.getLogger(PACKAGE_NAME + "." + self.entity_platform)
self._logger_is_debug = self._logger.isEnabledFor(logging.DEBUG)
Expand All @@ -61,12 +61,12 @@ def device_name(self):
name = self._device["object_name"]
return name

@cached_property
@property
def name(self):
"""Return the name of the device."""
return self.device_name

@cached_property
@property
def extra_state_attributes(self):
"""Return device specific state attributes."""
# see: https://developers.home-assistant.io/docs/dev_101_states/
Expand Down Expand Up @@ -172,7 +172,7 @@ def has_state(self, state):
else:
return False

@cached_property
@property
def icon(self):
"""Icon to use in the frontend, if any."""
if isinstance(self._device["icon"], str):
Expand All @@ -184,12 +184,12 @@ def icon(self):

return self.ICON

@cached_property
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return self._device["device_class"]

@cached_property
@property
def unique_id(self):
"""Return the ID of this device."""
# self._logger.debug("Unique Id: " + DOMAIN + '_' + self._platform + '_' + self._device_id + " - " + self.name)
Expand All @@ -201,12 +201,12 @@ def unique_id(self):
def _reset_status(self):
"""Set status from _device to class variables."""

@cached_property
@property
def is_default_state(self):
"""Return True of in default state - resulting in default icon."""
return False

@cached_property
@property
def device_info(self) -> DeviceInfo | None:
room_name = None
if (
Expand Down Expand Up @@ -275,22 +275,22 @@ def __init__(self, coordinator: VimarDataUpdateCoordinator):
self._data = self._attributes
self._state = False

@cached_property
@property
def device_class(self):
"""Return the class of this sensor."""
return self._type

@cached_property
@property
def should_poll(self):
"""Polling needed for a demo binary sensor."""
return True

@cached_property
@property
def name(self):
"""Return the name of the binary sensor."""
return self._name

@cached_property
@property
def unique_id(self):
"""Return the ID of this device."""
# self._logger.debug("Unique Id: " + DOMAIN + '_' + self._platform + '_' + self._device_id + " - " + self.name)
Expand All @@ -307,12 +307,12 @@ def device_state_attributes(self):
else:
return None

@cached_property
@property
def extra_state_attributes(self):
"""Return device specific state attributes."""
return self._attributes

@cached_property
@property
def device_info(self):
return {
"identifiers": {
Expand All @@ -323,7 +323,7 @@ def device_info(self):
"manufacturer": "Vimar",
}

@cached_property
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self._state
Expand Down
Loading

0 comments on commit da37865

Please sign in to comment.