diff --git a/homeassistant/components/netatmo/climate.py b/homeassistant/components/netatmo/climate.py index 1fb49d0c90d387c83cd0facf6846cf49b691ca2f..763ecdbc8ef51661b9729fa98040ee6758e7e0c7 100644 --- a/homeassistant/components/netatmo/climate.py +++ b/homeassistant/components/netatmo/climate.py @@ -506,7 +506,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity): self._target_temperature = roomstatus["target_temperature"] self._preset = NETATMO_MAP_PRESET[roomstatus["setpoint_mode"]] 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._away = self._hvac_mode == HVAC_MAP_NETATMO[STATE_NETATMO_AWAY] @@ -546,7 +546,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity): roomstatus["heating_status"] = self._boilerstatus batterylevel = self._home_status.thermostats[ roomstatus["module_id"] - ].get("battery_level") + ].get("battery_state") elif roomstatus["module_type"] == NA_VALVE: roomstatus["heating_power_request"] = self._room_status[ "heating_power_request" @@ -557,16 +557,11 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity): self._boilerstatus and roomstatus["heating_status"] ) batterylevel = self._home_status.valves[roomstatus["module_id"]].get( - "battery_level" + "battery_state" ) if batterylevel: - batterypct = interpolate(batterylevel, roomstatus["module_type"]) - if ( - not roomstatus.get("battery_level") - or batterypct < roomstatus["battery_level"] - ): - roomstatus["battery_level"] = batterypct + roomstatus["battery_state"] = batterylevel return roomstatus @@ -602,48 +597,6 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity): 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]: """Get all the home ids returned by NetAtmo API.""" if home_data is None: diff --git a/tests/components/netatmo/test_climate.py b/tests/components/netatmo/test_climate.py index ecec2871df895ae56b33a497344d5f80a7b13f07..a3cad1e6d81b233f9ba25a494f441b09fc8266ee 100644 --- a/tests/components/netatmo/test_climate.py +++ b/tests/components/netatmo/test_climate.py @@ -1,8 +1,6 @@ """The tests for the Netatmo climate platform.""" from unittest.mock import Mock, patch -import pytest - from homeassistant.components.climate import ( DOMAIN as CLIMATE_DOMAIN, SERVICE_SET_HVAC_MODE, @@ -21,12 +19,7 @@ from homeassistant.components.climate.const import ( PRESET_BOOST, ) from homeassistant.components.netatmo import climate -from homeassistant.components.netatmo.climate import ( - NA_THERM, - NA_VALVE, - PRESET_FROST_GUARD, - PRESET_SCHEDULE, -) +from homeassistant.components.netatmo.climate import PRESET_FROST_GUARD, PRESET_SCHEDULE from homeassistant.components.netatmo.const import ( ATTR_SCHEDULE_NAME, 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" -@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(): """Test extracting all home ids returned by NetAtmo API.""" # Test with backend returning no data