mirror of
https://github.com/home-assistant/core.git
synced 2026-04-17 15:44:52 +01:00
Replace deprecated library call in Velux integration (#165996)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -4,8 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from pyvlx.exception import PyVLXException
|
||||
from pyvlx.opening_device import OpeningDevice, Window
|
||||
from pyvlx import OpeningDevice, Position, PyVLXException, Window
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
@@ -55,7 +54,7 @@ class VeluxRainSensor(VeluxEntity, BinarySensorEntity):
|
||||
async def async_update(self) -> None:
|
||||
"""Fetch the latest state from the device."""
|
||||
try:
|
||||
limitation = await self.node.get_limitation()
|
||||
limitation: Position = await self.node.get_limitation_min()
|
||||
except (OSError, PyVLXException) as err:
|
||||
if not self._unavailable_logged:
|
||||
LOGGER.warning(
|
||||
@@ -78,4 +77,4 @@ class VeluxRainSensor(VeluxEntity, BinarySensorEntity):
|
||||
# So far we've seen 89, 91, 93 (most cases) or 100 (Velux GPU). It probably makes sense to
|
||||
# assume that any large enough limitation (we use >=89) means rain is detected.
|
||||
# Documentation on this is non-existent AFAIK.
|
||||
self._attr_is_on = limitation.min_value >= 89
|
||||
self._attr_is_on = limitation.position_percent >= 89
|
||||
|
||||
@@ -70,7 +70,7 @@ def mock_window() -> AsyncMock:
|
||||
window.name = "Test Window"
|
||||
window.rain_sensor = True
|
||||
window.serial_number = "123456789"
|
||||
window.get_limitation.return_value = MagicMock(min_value=0)
|
||||
window.get_limitation_min.return_value = MagicMock(position_percent=0)
|
||||
window.device_updated_cbs = []
|
||||
window.is_opening = False
|
||||
window.is_closing = False
|
||||
|
||||
@@ -43,35 +43,35 @@ async def test_rain_sensor_state(
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# simulate rain detected (Velux GPU reports 100)
|
||||
mock_window.get_limitation.return_value.min_value = 100
|
||||
mock_window.get_limitation_min.return_value.position_percent = 100
|
||||
await update_polled_entities(hass, freezer)
|
||||
state = hass.states.get(test_entity_id)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
# simulate rain detected (most Velux models report 93)
|
||||
mock_window.get_limitation.return_value.min_value = 93
|
||||
mock_window.get_limitation_min.return_value.position_percent = 93
|
||||
await update_polled_entities(hass, freezer)
|
||||
state = hass.states.get(test_entity_id)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
# simulate rain detected (other Velux models report 89)
|
||||
mock_window.get_limitation.return_value.min_value = 89
|
||||
mock_window.get_limitation_min.return_value.position_percent = 89
|
||||
await update_polled_entities(hass, freezer)
|
||||
state = hass.states.get(test_entity_id)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
# simulate other limits which do not indicate rain detected
|
||||
mock_window.get_limitation.return_value.min_value = 88
|
||||
mock_window.get_limitation_min.return_value.position_percent = 88
|
||||
await update_polled_entities(hass, freezer)
|
||||
state = hass.states.get(test_entity_id)
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# simulate no rain detected again
|
||||
mock_window.get_limitation.return_value.min_value = 0
|
||||
mock_window.get_limitation_min.return_value.position_percent = 0
|
||||
await update_polled_entities(hass, freezer)
|
||||
state = hass.states.get(test_entity_id)
|
||||
assert state is not None
|
||||
@@ -133,7 +133,7 @@ async def test_rain_sensor_unavailability(
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Simulate communication error
|
||||
mock_window.get_limitation.side_effect = PyVLXException("Connection failed")
|
||||
mock_window.get_limitation_min.side_effect = PyVLXException("Connection failed")
|
||||
await update_polled_entities(hass, freezer)
|
||||
|
||||
# Entity should now be unavailable
|
||||
@@ -157,8 +157,8 @@ async def test_rain_sensor_unavailability(
|
||||
caplog.clear()
|
||||
|
||||
# Simulate recovery
|
||||
mock_window.get_limitation.side_effect = None
|
||||
mock_window.get_limitation.return_value.min_value = 0
|
||||
mock_window.get_limitation_min.side_effect = None
|
||||
mock_window.get_limitation_min.return_value.position_percent = 0
|
||||
await update_polled_entities(hass, freezer)
|
||||
|
||||
# Entity should be available again
|
||||
|
||||
Reference in New Issue
Block a user