mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Fix battery attribute (#50405)
This commit is contained in:
parent
84984b0223
commit
12342437e2
@ -506,7 +506,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
self._target_temperature = roomstatus["target_temperature"]
|
self._target_temperature = roomstatus["target_temperature"]
|
||||||
self._preset = NETATMO_MAP_PRESET[roomstatus["setpoint_mode"]]
|
self._preset = NETATMO_MAP_PRESET[roomstatus["setpoint_mode"]]
|
||||||
self._hvac_mode = HVAC_MAP_NETATMO[self._preset]
|
self._hvac_mode = HVAC_MAP_NETATMO[self._preset]
|
||||||
self._battery_level = roomstatus.get("battery_level")
|
self._battery_level = roomstatus.get("battery_state")
|
||||||
self._connected = True
|
self._connected = True
|
||||||
|
|
||||||
self._away = self._hvac_mode == HVAC_MAP_NETATMO[STATE_NETATMO_AWAY]
|
self._away = self._hvac_mode == HVAC_MAP_NETATMO[STATE_NETATMO_AWAY]
|
||||||
@ -546,7 +546,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
roomstatus["heating_status"] = self._boilerstatus
|
roomstatus["heating_status"] = self._boilerstatus
|
||||||
batterylevel = self._home_status.thermostats[
|
batterylevel = self._home_status.thermostats[
|
||||||
roomstatus["module_id"]
|
roomstatus["module_id"]
|
||||||
].get("battery_level")
|
].get("battery_state")
|
||||||
elif roomstatus["module_type"] == NA_VALVE:
|
elif roomstatus["module_type"] == NA_VALVE:
|
||||||
roomstatus["heating_power_request"] = self._room_status[
|
roomstatus["heating_power_request"] = self._room_status[
|
||||||
"heating_power_request"
|
"heating_power_request"
|
||||||
@ -557,16 +557,11 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
self._boilerstatus and roomstatus["heating_status"]
|
self._boilerstatus and roomstatus["heating_status"]
|
||||||
)
|
)
|
||||||
batterylevel = self._home_status.valves[roomstatus["module_id"]].get(
|
batterylevel = self._home_status.valves[roomstatus["module_id"]].get(
|
||||||
"battery_level"
|
"battery_state"
|
||||||
)
|
)
|
||||||
|
|
||||||
if batterylevel:
|
if batterylevel:
|
||||||
batterypct = interpolate(batterylevel, roomstatus["module_type"])
|
roomstatus["battery_state"] = batterylevel
|
||||||
if (
|
|
||||||
not roomstatus.get("battery_level")
|
|
||||||
or batterypct < roomstatus["battery_level"]
|
|
||||||
):
|
|
||||||
roomstatus["battery_level"] = batterypct
|
|
||||||
|
|
||||||
return roomstatus
|
return roomstatus
|
||||||
|
|
||||||
@ -602,48 +597,6 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
return {**super().device_info, "suggested_area": self._room_data["name"]}
|
return {**super().device_info, "suggested_area": self._room_data["name"]}
|
||||||
|
|
||||||
|
|
||||||
def interpolate(batterylevel: int, module_type: str) -> int:
|
|
||||||
"""Interpolate battery level depending on device type."""
|
|
||||||
na_battery_levels = {
|
|
||||||
NA_THERM: {
|
|
||||||
"full": 4100,
|
|
||||||
"high": 3600,
|
|
||||||
"medium": 3300,
|
|
||||||
"low": 3000,
|
|
||||||
"empty": 2800,
|
|
||||||
},
|
|
||||||
NA_VALVE: {
|
|
||||||
"full": 3200,
|
|
||||||
"high": 2700,
|
|
||||||
"medium": 2400,
|
|
||||||
"low": 2200,
|
|
||||||
"empty": 2200,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
levels = sorted(na_battery_levels[module_type].values())
|
|
||||||
steps = [20, 50, 80, 100]
|
|
||||||
|
|
||||||
na_battery_level = na_battery_levels[module_type]
|
|
||||||
if batterylevel >= na_battery_level["full"]:
|
|
||||||
return 100
|
|
||||||
if batterylevel >= na_battery_level["high"]:
|
|
||||||
i = 3
|
|
||||||
elif batterylevel >= na_battery_level["medium"]:
|
|
||||||
i = 2
|
|
||||||
elif batterylevel >= na_battery_level["low"]:
|
|
||||||
i = 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
pct = steps[i - 1] + (
|
|
||||||
(steps[i] - steps[i - 1])
|
|
||||||
* (batterylevel - levels[i])
|
|
||||||
/ (levels[i + 1] - levels[i])
|
|
||||||
)
|
|
||||||
return int(pct)
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_home_ids(home_data: pyatmo.HomeData) -> list[str]:
|
def get_all_home_ids(home_data: pyatmo.HomeData) -> list[str]:
|
||||||
"""Get all the home ids returned by NetAtmo API."""
|
"""Get all the home ids returned by NetAtmo API."""
|
||||||
if home_data is None:
|
if home_data is None:
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
"""The tests for the Netatmo climate platform."""
|
"""The tests for the Netatmo climate platform."""
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
DOMAIN as CLIMATE_DOMAIN,
|
DOMAIN as CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
@ -21,12 +19,7 @@ from homeassistant.components.climate.const import (
|
|||||||
PRESET_BOOST,
|
PRESET_BOOST,
|
||||||
)
|
)
|
||||||
from homeassistant.components.netatmo import climate
|
from homeassistant.components.netatmo import climate
|
||||||
from homeassistant.components.netatmo.climate import (
|
from homeassistant.components.netatmo.climate import PRESET_FROST_GUARD, PRESET_SCHEDULE
|
||||||
NA_THERM,
|
|
||||||
NA_VALVE,
|
|
||||||
PRESET_FROST_GUARD,
|
|
||||||
PRESET_SCHEDULE,
|
|
||||||
)
|
|
||||||
from homeassistant.components.netatmo.const import (
|
from homeassistant.components.netatmo.const import (
|
||||||
ATTR_SCHEDULE_NAME,
|
ATTR_SCHEDULE_NAME,
|
||||||
SERVICE_SET_SCHEDULE,
|
SERVICE_SET_SCHEDULE,
|
||||||
@ -653,28 +646,6 @@ async def test_valves_service_turn_on(hass, climate_entry):
|
|||||||
assert hass.states.get(climate_entity_entrada).state == "auto"
|
assert hass.states.get(climate_entity_entrada).state == "auto"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"batterylevel, module_type, expected",
|
|
||||||
[
|
|
||||||
(4101, NA_THERM, 100),
|
|
||||||
(3601, NA_THERM, 80),
|
|
||||||
(3450, NA_THERM, 65),
|
|
||||||
(3301, NA_THERM, 50),
|
|
||||||
(3001, NA_THERM, 20),
|
|
||||||
(2799, NA_THERM, 0),
|
|
||||||
(3201, NA_VALVE, 100),
|
|
||||||
(2701, NA_VALVE, 80),
|
|
||||||
(2550, NA_VALVE, 65),
|
|
||||||
(2401, NA_VALVE, 50),
|
|
||||||
(2201, NA_VALVE, 20),
|
|
||||||
(2001, NA_VALVE, 0),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_interpolate(batterylevel, module_type, expected):
|
|
||||||
"""Test interpolation of battery levels depending on device type."""
|
|
||||||
assert climate.interpolate(batterylevel, module_type) == expected
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_all_home_ids():
|
async def test_get_all_home_ids():
|
||||||
"""Test extracting all home ids returned by NetAtmo API."""
|
"""Test extracting all home ids returned by NetAtmo API."""
|
||||||
# Test with backend returning no data
|
# Test with backend returning no data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user