mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use the humidity value in Shelly Wall Display climate entity (#119830)
* Use the humidity value with the climate entity if available * Update tests * Use walrus --------- Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
b6b6248713
commit
f5dfefb3a6
@ -468,6 +468,10 @@ class RpcClimate(ShellyRpcEntity, ClimateEntity):
|
|||||||
self._attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL]
|
self._attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL]
|
||||||
else:
|
else:
|
||||||
self._attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT]
|
self._attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT]
|
||||||
|
self._humidity_key: str | None = None
|
||||||
|
# Check if there is a corresponding humidity key for the thermostat ID
|
||||||
|
if (humidity_key := f"humidity:{id_}") in self.coordinator.device.status:
|
||||||
|
self._humidity_key = humidity_key
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self) -> float | None:
|
def target_temperature(self) -> float | None:
|
||||||
@ -479,6 +483,14 @@ class RpcClimate(ShellyRpcEntity, ClimateEntity):
|
|||||||
"""Return current temperature."""
|
"""Return current temperature."""
|
||||||
return cast(float, self.status["current_C"])
|
return cast(float, self.status["current_C"])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_humidity(self) -> float | None:
|
||||||
|
"""Return current humidity."""
|
||||||
|
if self._humidity_key is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return cast(float, self.coordinator.device.status[self._humidity_key]["rh"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> HVACMode:
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""HVAC current mode."""
|
"""HVAC current mode."""
|
||||||
|
@ -254,6 +254,7 @@ MOCK_STATUS_RPC = {
|
|||||||
"current_C": 12.3,
|
"current_C": 12.3,
|
||||||
"output": True,
|
"output": True,
|
||||||
},
|
},
|
||||||
|
"humidity:0": {"rh": 44.4},
|
||||||
"sys": {
|
"sys": {
|
||||||
"available_updates": {
|
"available_updates": {
|
||||||
"beta": {"version": "some_beta_version"},
|
"beta": {"version": "some_beta_version"},
|
||||||
|
@ -8,6 +8,7 @@ from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
|
ATTR_CURRENT_HUMIDITY,
|
||||||
ATTR_CURRENT_TEMPERATURE,
|
ATTR_CURRENT_TEMPERATURE,
|
||||||
ATTR_HVAC_ACTION,
|
ATTR_HVAC_ACTION,
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
@ -610,6 +611,7 @@ async def test_rpc_climate_hvac_mode(
|
|||||||
assert state.attributes[ATTR_TEMPERATURE] == 23
|
assert state.attributes[ATTR_TEMPERATURE] == 23
|
||||||
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 12.3
|
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 12.3
|
||||||
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
|
||||||
|
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 44.4
|
||||||
|
|
||||||
entry = entity_registry.async_get(ENTITY_ID)
|
entry = entity_registry.async_get(ENTITY_ID)
|
||||||
assert entry
|
assert entry
|
||||||
@ -620,6 +622,7 @@ async def test_rpc_climate_hvac_mode(
|
|||||||
|
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(ENTITY_ID)
|
||||||
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
|
||||||
|
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 44.4
|
||||||
|
|
||||||
monkeypatch.setitem(mock_rpc_device.status["thermostat:0"], "enable", False)
|
monkeypatch.setitem(mock_rpc_device.status["thermostat:0"], "enable", False)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -637,6 +640,31 @@ async def test_rpc_climate_hvac_mode(
|
|||||||
assert state.state == HVACMode.OFF
|
assert state.state == HVACMode.OFF
|
||||||
|
|
||||||
|
|
||||||
|
async def test_rpc_climate_without_humidity(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: EntityRegistry,
|
||||||
|
mock_rpc_device: Mock,
|
||||||
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
|
) -> None:
|
||||||
|
"""Test climate entity without the humidity value."""
|
||||||
|
new_status = deepcopy(mock_rpc_device.status)
|
||||||
|
new_status.pop("humidity:0")
|
||||||
|
monkeypatch.setattr(mock_rpc_device, "status", new_status)
|
||||||
|
|
||||||
|
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
|
||||||
|
|
||||||
|
state = hass.states.get(ENTITY_ID)
|
||||||
|
assert state.state == HVACMode.HEAT
|
||||||
|
assert state.attributes[ATTR_TEMPERATURE] == 23
|
||||||
|
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 12.3
|
||||||
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING
|
||||||
|
assert ATTR_CURRENT_HUMIDITY not in state.attributes
|
||||||
|
|
||||||
|
entry = entity_registry.async_get(ENTITY_ID)
|
||||||
|
assert entry
|
||||||
|
assert entry.unique_id == "123456789ABC-thermostat:0"
|
||||||
|
|
||||||
|
|
||||||
async def test_rpc_climate_set_temperature(
|
async def test_rpc_climate_set_temperature(
|
||||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user