From bf07de4bfe0c5e144a4068566de25b5e88df34aa Mon Sep 17 00:00:00 2001 From: Dusan Date: Wed, 13 Nov 2024 20:00:03 +0100 Subject: [PATCH 1/5] turn on hvac when setting temp (if hvac is off) Signed-off-by: Dusan --- custom_components/fujitsu_airstage/climate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/fujitsu_airstage/climate.py b/custom_components/fujitsu_airstage/climate.py index 491c77d..8a9c444 100644 --- a/custom_components/fujitsu_airstage/climate.py +++ b/custom_components/fujitsu_airstage/climate.py @@ -152,6 +152,8 @@ def target_temperature(self) -> float | None: async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" + if self.hvac_mode == HVACMode.OFF: + await self.async_turn_on() if self.hvac_mode != HVACMode.FAN_ONLY: await self._ac.set_target_temperature(kwargs.get(ATTR_TEMPERATURE)) From 0f613071bc01ce88ffdf8ad4d35b2ac9b5bf16b6 Mon Sep 17 00:00:00 2001 From: Dusan Date: Wed, 13 Nov 2024 22:24:18 +0100 Subject: [PATCH 2/5] Add options flow for turning on AC before setting temperature Signed-off-by: Dusan --- custom_components/fujitsu_airstage/climate.py | 15 +++++-- .../fujitsu_airstage/config_flow.py | 40 +++++++++++++++++++ custom_components/fujitsu_airstage/const.py | 1 + .../fujitsu_airstage/strings.json | 9 ++++- .../fujitsu_airstage/translations/en.json | 11 ++++- 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/custom_components/fujitsu_airstage/climate.py b/custom_components/fujitsu_airstage/climate.py index 8a9c444..1df4b4b 100644 --- a/custom_components/fujitsu_airstage/climate.py +++ b/custom_components/fujitsu_airstage/climate.py @@ -32,6 +32,7 @@ VERTICAL_LOWEST, VERTICAL_SWING, MINIMUM_HEAT, + CONF_TURN_ON_BEFORE_SET_TEMP, ) HA_STATE_TO_FUJITSU = { @@ -101,15 +102,21 @@ async def async_setup_entry( config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: + config_entry.async_on_unload(config_entry.add_update_listener(update_listener)) + instance: AirstageData = hass.data[AIRSTAGE_DOMAIN][config_entry.entry_id] entities: list[ClimateEntity] = [] if devices := instance.coordinator.data: for ac_key in devices: - entities.append(AirstageAC(instance, ac_key)) + entities.append(AirstageAC(instance, ac_key, config_entry)) async_add_entities(entities) +async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None: + """Update listener.""" + await hass.config_entries.async_reload(config_entry.entry_id) + class AirstageAC(AirstageAcEntity, ClimateEntity): """Airstage unit.""" @@ -122,6 +129,7 @@ class AirstageAC(AirstageAcEntity, ClimateEntity): _attr_max_temp = 32 _attr_min_temp = 16 _attr_name = None + _turn_on_before_set_temp = False _attr_fan_modes = [FAN_QUIET, FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO] @@ -134,9 +142,10 @@ class AirstageAC(AirstageAcEntity, ClimateEntity): HVACMode.AUTO, ] - def __init__(self, instance: AirstageData, ac_key: str) -> None: + def __init__(self, instance: AirstageData, ac_key: str, config_entry: ConfigEntry) -> None: """Initialize an AdvantageAir AC unit.""" super().__init__(instance, ac_key) + self._turn_on_before_set_temp = config_entry.options.get(CONF_TURN_ON_BEFORE_SET_TEMP, False) @property def target_temperature(self) -> float | None: @@ -152,7 +161,7 @@ def target_temperature(self) -> float | None: async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" - if self.hvac_mode == HVACMode.OFF: + if self._turn_on_before_set_temp and self.hvac_mode == HVACMode.OFF: await self.async_turn_on() if self.hvac_mode != HVACMode.FAN_ONLY: diff --git a/custom_components/fujitsu_airstage/config_flow.py b/custom_components/fujitsu_airstage/config_flow.py index 6912b75..0776ebd 100644 --- a/custom_components/fujitsu_airstage/config_flow.py +++ b/custom_components/fujitsu_airstage/config_flow.py @@ -9,6 +9,7 @@ from homeassistant import config_entries from homeassistant.core import HomeAssistant +from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -33,10 +34,40 @@ CONF_SELECT_POLLING, CONF_SELECT_POLLING_DESCRIPTION, DOMAIN, + CONF_TURN_ON_BEFORE_SET_TEMP, ) _LOGGER = logging.getLogger(__name__) +class OptionsFlow(config_entries.OptionsFlow): + """Handle a options flow for Airstage Fujitsu.""" + + def __init__(self, config_entry: config_entries.ConfigEntry): + """Initialize the options flow.""" + self._config_entry = config_entry + + async def async_step_init( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: + """Manage the options.""" + if user_input is not None: + return self.async_create_entry(data=user_input) + + options_schema = { + vol.Optional( + CONF_TURN_ON_BEFORE_SET_TEMP, + default=self._config_entry.options.get( + CONF_TURN_ON_BEFORE_SET_TEMP, + False + ), + ): bool, + } + + + return self.async_show_form( + step_id="init", + data_schema=vol.Schema(options_schema), + ) class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow for Airstage Fujitsu.""" @@ -50,6 +81,15 @@ def __init__(self) -> None: self.country = None self.device_id = None self.ip_address = None + self.turn_on_before_set_temp = False + + @staticmethod + @callback + def async_get_options_flow( + config_entry: config_entries.ConfigEntry, + ) -> ConfigFlow: + """Get the Frigate Options flow.""" + return OptionsFlow(config_entry) async def async_step_details( self, user_input: dict[str, Any] | None = None diff --git a/custom_components/fujitsu_airstage/const.py b/custom_components/fujitsu_airstage/const.py index 989d992..b2a2e78 100644 --- a/custom_components/fujitsu_airstage/const.py +++ b/custom_components/fujitsu_airstage/const.py @@ -25,3 +25,4 @@ CONF_CLOUD = "cloud" CONF_SELECT_POLLING = "select_polling" CONF_SELECT_POLLING_DESCRIPTION = "select_polling_desc" +CONF_TURN_ON_BEFORE_SET_TEMP = "conf_turn_on_before_set_temp" diff --git a/custom_components/fujitsu_airstage/strings.json b/custom_components/fujitsu_airstage/strings.json index c217cbb..dd550ef 100644 --- a/custom_components/fujitsu_airstage/strings.json +++ b/custom_components/fujitsu_airstage/strings.json @@ -1,4 +1,11 @@ { + "options": { + "step": { + "init": { + "conf_turn_on_before_set_temp": "[%key:common::config_flow::data::conf_turn_on_before_set_temp]" + } + } + }, "config": { "step": { "details": { @@ -35,4 +42,4 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } } -} \ No newline at end of file +} diff --git a/custom_components/fujitsu_airstage/translations/en.json b/custom_components/fujitsu_airstage/translations/en.json index 5c667e2..2847422 100644 --- a/custom_components/fujitsu_airstage/translations/en.json +++ b/custom_components/fujitsu_airstage/translations/en.json @@ -1,4 +1,13 @@ { + "options": { + "step": { + "init": { + "data": { + "conf_turn_on_before_set_temp": "Turn on AC before setting temperature" + } + } + } + }, "config": { "abort": { "already_configured": "Device is already configured" @@ -33,4 +42,4 @@ } } } -} \ No newline at end of file +} From 90a3aec1868996704c7965a0f9d909b17ce8918d Mon Sep 17 00:00:00 2001 From: Dusan Date: Wed, 13 Nov 2024 22:28:49 +0100 Subject: [PATCH 3/5] Fix incorrect type annotation Signed-off-by: Dusan --- custom_components/fujitsu_airstage/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/fujitsu_airstage/config_flow.py b/custom_components/fujitsu_airstage/config_flow.py index 0776ebd..8483dfe 100644 --- a/custom_components/fujitsu_airstage/config_flow.py +++ b/custom_components/fujitsu_airstage/config_flow.py @@ -87,7 +87,7 @@ def __init__(self) -> None: @callback def async_get_options_flow( config_entry: config_entries.ConfigEntry, - ) -> ConfigFlow: + ) -> OptionsFlow: """Get the Frigate Options flow.""" return OptionsFlow(config_entry) From 68fc981dd90bba9ebc78de0ac7eb3c1a942774c3 Mon Sep 17 00:00:00 2001 From: Dusan Date: Wed, 13 Nov 2024 22:31:39 +0100 Subject: [PATCH 4/5] Fix incorrect strings path Signed-off-by: Dusan --- custom_components/fujitsu_airstage/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/fujitsu_airstage/strings.json b/custom_components/fujitsu_airstage/strings.json index dd550ef..4c0c406 100644 --- a/custom_components/fujitsu_airstage/strings.json +++ b/custom_components/fujitsu_airstage/strings.json @@ -2,7 +2,7 @@ "options": { "step": { "init": { - "conf_turn_on_before_set_temp": "[%key:common::config_flow::data::conf_turn_on_before_set_temp]" + "conf_turn_on_before_set_temp": "[%key:common::config_flow::options::conf_turn_on_before_set_temp]" } } }, From 57b7327ca40a05affdf45906c79c947487630aee Mon Sep 17 00:00:00 2001 From: Dusan Date: Mon, 18 Nov 2024 09:10:56 +0100 Subject: [PATCH 5/5] Update translation for conf_turn_on_before_set_temp Signed-off-by: Dusan --- custom_components/fujitsu_airstage/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/fujitsu_airstage/translations/en.json b/custom_components/fujitsu_airstage/translations/en.json index 2847422..6d3cfe4 100644 --- a/custom_components/fujitsu_airstage/translations/en.json +++ b/custom_components/fujitsu_airstage/translations/en.json @@ -3,7 +3,7 @@ "step": { "init": { "data": { - "conf_turn_on_before_set_temp": "Turn on AC before setting temperature" + "conf_turn_on_before_set_temp": "Turn on device before setting temperature" } } }