Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turn on hvac when setting temp (if hvac is off) #40

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions custom_components/fujitsu_airstage/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
VERTICAL_LOWEST,
VERTICAL_SWING,
MINIMUM_HEAT,
CONF_TURN_ON_BEFORE_SET_TEMP,
)

HA_STATE_TO_FUJITSU = {
Expand Down Expand Up @@ -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."""
Expand All @@ -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]

Expand All @@ -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:
Expand All @@ -152,6 +161,8 @@ def target_temperature(self) -> float | None:

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
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:
await self._ac.set_target_temperature(kwargs.get(ATTR_TEMPERATURE))
Expand Down
40 changes: 40 additions & 0 deletions custom_components/fujitsu_airstage/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand All @@ -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,
) -> OptionsFlow:
"""Get the Frigate Options flow."""
return OptionsFlow(config_entry)

async def async_step_details(
self, user_input: dict[str, Any] | None = None
Expand Down
1 change: 1 addition & 0 deletions custom_components/fujitsu_airstage/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 8 additions & 1 deletion custom_components/fujitsu_airstage/strings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"options": {
"step": {
"init": {
"conf_turn_on_before_set_temp": "[%key:common::config_flow::options::conf_turn_on_before_set_temp]"
}
}
},
"config": {
"step": {
"details": {
Expand Down Expand Up @@ -35,4 +42,4 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
}
}
}
11 changes: 10 additions & 1 deletion custom_components/fujitsu_airstage/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"options": {
"step": {
"init": {
"data": {
"conf_turn_on_before_set_temp": "Turn on device before setting temperature"
}
}
}
},
"config": {
"abort": {
"already_configured": "Device is already configured"
Expand Down Expand Up @@ -33,4 +42,4 @@
}
}
}
}
}