diff --git a/homeassistant/components/screenlogic/climate.py b/homeassistant/components/screenlogic/climate.py index c0cff8d511b..e44d9b18ae1 100644 --- a/homeassistant/components/screenlogic/climate.py +++ b/homeassistant/components/screenlogic/climate.py @@ -93,7 +93,7 @@ class ScreenLogicClimate(ScreenLogicPushEntity, ClimateEntity, RestoreEntity): ) self._configured_heat_modes.append(HEAT_MODE.HEATER) self._attr_preset_modes = [ - HEAT_MODE(mode_num).title for mode_num in self._configured_heat_modes + HEAT_MODE(mode_num).name.lower() for mode_num in self._configured_heat_modes ] self._attr_min_temp = self.entity_data[ATTR.MIN_SETPOINT] @@ -137,8 +137,8 @@ class ScreenLogicClimate(ScreenLogicPushEntity, ClimateEntity, RestoreEntity): def preset_mode(self) -> str: """Return current/last preset mode.""" if self.hvac_mode == HVACMode.OFF: - return HEAT_MODE(self._last_preset).title - return HEAT_MODE(self.entity_data[VALUE.HEAT_MODE][ATTR.VALUE]).title + return HEAT_MODE(self._last_preset).name.lower() + return HEAT_MODE(self.entity_data[VALUE.HEAT_MODE][ATTR.VALUE]).name.lower() async def async_set_temperature(self, **kwargs: Any) -> None: """Change the setpoint of the heater.""" diff --git a/homeassistant/components/screenlogic/sensor.py b/homeassistant/components/screenlogic/sensor.py index 6ae6e802859..df6c5ef7acb 100644 --- a/homeassistant/components/screenlogic/sensor.py +++ b/homeassistant/components/screenlogic/sensor.py @@ -189,8 +189,8 @@ SUPPORTED_INTELLICHEM_SENSORS = [ data_root=(DEVICE.INTELLICHEM, GROUP.DOSE_STATUS), key=VALUE.ORP_DOSING_STATE, device_class=SensorDeviceClass.ENUM, - options=["Dosing", "Mixing", "Monitoring"], - value_mod=lambda val: DOSE_STATE(val).title, + options=["dosing", "mixing", "monitoring"], + value_mod=lambda val: DOSE_STATE(val).name.lower(), translation_key="chem_dose_state", translation_placeholders={"chem": "ORP"}, ), @@ -217,8 +217,8 @@ SUPPORTED_INTELLICHEM_SENSORS = [ data_root=(DEVICE.INTELLICHEM, GROUP.DOSE_STATUS), key=VALUE.PH_DOSING_STATE, device_class=SensorDeviceClass.ENUM, - options=["Dosing", "Mixing", "Monitoring"], - value_mod=lambda val: DOSE_STATE(val).title, + options=["dosing", "mixing", "monitoring"], + value_mod=lambda val: DOSE_STATE(val).name.lower(), translation_key="chem_dose_state", translation_placeholders={"chem": "pH"}, ), diff --git a/homeassistant/components/screenlogic/strings.json b/homeassistant/components/screenlogic/strings.json index da5e3156592..1f5695d6613 100644 --- a/homeassistant/components/screenlogic/strings.json +++ b/homeassistant/components/screenlogic/strings.json @@ -3,8 +3,9 @@ "service_config_entry_name": "Config entry", "service_config_entry_description": "The config entry to use for this action.", "climate_preset_solar": "Solar", - "climate_preset_solar_prefered": "Solar Prefered", - "climate_preset_heater": "Heater" + "climate_preset_solar_preferred": "Solar Preferred", + "climate_preset_heater": "Heater", + "climate_preset_dont_change": "Don't Change" }, "config": { "flow_title": "{name}", @@ -133,10 +134,30 @@ }, "climate": { "body_0": { - "name": "Pool heat" + "name": "Pool heat", + "state_attributes": { + "preset_mode": { + "state": { + "solar": "[%key:component::screenlogic::common::climate_preset_solar%]", + "solar_preferred": "[%key:component::screenlogic::common::climate_preset_solar_preferred%]", + "heater": "[%key:component::screenlogic::common::climate_preset_heater%]", + "dont_change": "[%key:component::screenlogic::common::climate_preset_dont_change%]" + } + } + } }, "body_1": { - "name": "Spa heat" + "name": "Spa heat", + "state_attributes": { + "preset_mode": { + "state": { + "solar": "[%key:component::screenlogic::common::climate_preset_solar%]", + "solar_preferred": "[%key:component::screenlogic::common::climate_preset_solar_preferred%]", + "heater": "[%key:component::screenlogic::common::climate_preset_heater%]", + "dont_change": "[%key:component::screenlogic::common::climate_preset_dont_change%]" + } + } + } } }, "number": { @@ -191,7 +212,12 @@ "name": "[%key:component::screenlogic::entity::number::salt_tds_ppm::name%]" }, "chem_dose_state": { - "name": "{chem} dosing state" + "name": "{chem} dosing state", + "state": { + "dosing": "Dosing", + "mixing": "Mixing", + "monitoring": "Monitoring" + } }, "chem_last_dose_time": { "name": "{chem} last dose time" diff --git a/tests/components/screenlogic/fixtures/data_missing_values_chem_chlor.json b/tests/components/screenlogic/fixtures/data_missing_values_chem_chlor.json index aa0df6e3df6..04437c12ebf 100644 --- a/tests/components/screenlogic/fixtures/data_missing_values_chem_chlor.json +++ b/tests/components/screenlogic/fixtures/data_missing_values_chem_chlor.json @@ -619,7 +619,7 @@ }, "heat_mode": { "name": "Spa Heat Mode", - "value": 0, + "value": 3, "device_type": "enum", "enum_options": [ "Off", diff --git a/tests/components/screenlogic/test_climate.py b/tests/components/screenlogic/test_climate.py new file mode 100644 index 00000000000..c2e96a35508 --- /dev/null +++ b/tests/components/screenlogic/test_climate.py @@ -0,0 +1,103 @@ +"""Tests for ScreenLogic climate entity.""" + +import logging +from unittest.mock import DEFAULT, patch + +import pytest +from screenlogicpy import ScreenLogicGateway +from screenlogicpy.device_const.heat import HEAT_MODE + +from homeassistant.components.climate import ( + ATTR_CURRENT_TEMPERATURE, + ATTR_HVAC_ACTION, + ATTR_HVAC_MODES, + ATTR_PRESET_MODE, + ATTR_PRESET_MODES, + ATTR_TEMPERATURE, + DOMAIN as CLIMATE_DOMAIN, + HVACAction, + HVACMode, +) +from homeassistant.core import HomeAssistant +from homeassistant.util import slugify + +from . import ( + DATA_MISSING_VALUES_CHEM_CHLOR, + GATEWAY_DISCOVERY_IMPORT_PATH, + MOCK_ADAPTER_NAME, + stub_async_connect, +) + +from tests.common import MockConfigEntry + +_LOGGER = logging.getLogger(__name__) + + +@pytest.mark.parametrize( + ( + "tested_dataset", + "expected_entity_states", + ), + [ + ( + DATA_MISSING_VALUES_CHEM_CHLOR, + { + f"{CLIMATE_DOMAIN}.{slugify(MOCK_ADAPTER_NAME)}_pool_heat": { + "state": HVACMode.OFF, + "attributes": { + ATTR_CURRENT_TEMPERATURE: 27.2, + ATTR_TEMPERATURE: 28.3, + ATTR_HVAC_ACTION: HVACAction.OFF, + ATTR_HVAC_MODES: [HVACMode.OFF, HVACMode.HEAT], + ATTR_PRESET_MODE: "heater", + ATTR_PRESET_MODES: [HEAT_MODE.HEATER.name.lower()], + }, + }, + f"{CLIMATE_DOMAIN}.{slugify(MOCK_ADAPTER_NAME)}_spa_heat": { + "state": HVACMode.HEAT, + "attributes": { + ATTR_CURRENT_TEMPERATURE: 28.9, + ATTR_TEMPERATURE: 34.4, + ATTR_HVAC_ACTION: HVACAction.IDLE, + ATTR_HVAC_MODES: [HVACMode.OFF, HVACMode.HEAT], + ATTR_PRESET_MODE: "heater", + ATTR_PRESET_MODES: [HEAT_MODE.HEATER.name.lower()], + }, + }, + }, + ) + ], +) +async def test_climate_state( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + tested_dataset: dict, + expected_entity_states: dict, +) -> None: + """Test setup for platforms that define expected data.""" + + def stub_connect(*args, **kwargs): + return stub_async_connect(tested_dataset, *args, **kwargs) + + mock_config_entry.add_to_hass(hass) + + with ( + patch( + GATEWAY_DISCOVERY_IMPORT_PATH, + return_value={}, + ), + patch.multiple( + ScreenLogicGateway, + async_connect=stub_connect, + is_connected=True, + _async_connected_request=DEFAULT, + ), + ): + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + for entity_id, state_data in expected_entity_states.items(): + assert (climate_state := hass.states.get(entity_id)) is not None + assert climate_state.state == state_data["state"] + for attribute, value in state_data["attributes"].items(): + assert climate_state.attributes[attribute] == value