Skip to content
Draft
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
8 changes: 8 additions & 0 deletions custom_components/smart_climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN][entry.entry_id] = entry.data

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

entry.async_on_unload(entry.add_update_listener(_async_update_listener))

return True


async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload entry when options are updated."""
await hass.config_entries.async_reload(entry.entry_id)


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
Expand Down
13 changes: 7 additions & 6 deletions custom_components/smart_climate/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ async def async_setup_entry(
name = entry.data.get(CONF_NAME, "Smart Climate")
wrapped_climate = entry.data.get(CONF_WRAPPED_CLIMATE)
zone_home = entry.data.get(CONF_ZONE_HOME)
away_temp = entry.data.get(CONF_AWAY_TEMPERATURE, 14)
auto_temp = entry.data.get(CONF_AUTO_TEMPERATURE, 21)
away_delay = entry.data.get(CONF_AWAY_DELAY_MINUTES, 5)
interruptible = entry.data.get(CONF_INTERRUPTIBLE, True)
default_override_mode = entry.data.get(CONF_DEFAULT_OVERRIDE_MODE, "timer")
default_override_duration = entry.data.get(CONF_DEFAULT_OVERRIDE_DURATION, 30)
options = {**entry.data, **entry.options}
away_temp = options.get(CONF_AWAY_TEMPERATURE, 14)
auto_temp = options.get(CONF_AUTO_TEMPERATURE, 21)
away_delay = options.get(CONF_AWAY_DELAY_MINUTES, 5)
interruptible = options.get(CONF_INTERRUPTIBLE, True)
default_override_mode = options.get(CONF_DEFAULT_OVERRIDE_MODE, "timer")
default_override_duration = options.get(CONF_DEFAULT_OVERRIDE_DURATION, 30)

entity = SmartClimateEntity(
hass,
Expand Down
55 changes: 54 additions & 1 deletion custom_components/smart_climate/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, OptionsFlow, ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.helpers import config_validation as cv
import voluptuous as vol
Expand All @@ -24,6 +24,11 @@ def __init__(self):
super().__init__()
self._import_name = None

@staticmethod
def async_get_options_flow(config_entry: ConfigEntry):
"""Return the options flow."""
return SmartClimateOptionsFlow(config_entry)

async def async_step_import(self, import_data):
"""Handle import from YAML (only name is required)."""
if isinstance(import_data, list):
Expand Down Expand Up @@ -89,4 +94,52 @@ async def async_step_reconfigure(self, user_input=None):
return self.async_show_form(
step_id="reconfigure",
data_schema=schema,
)


class SmartClimateOptionsFlow(OptionsFlow):
"""Options flow for Smart Climate — change settings after initial setup."""

def __init__(self, config_entry: ConfigEntry):
self._config_entry = config_entry

async def async_step_init(self, user_input=None):
"""Handle options step."""
current = {**self._config_entry.data, **self._config_entry.options}

if user_input is not None:
return self.async_create_entry(title="", data=user_input)

schema = vol.Schema(
{
vol.Optional(
CONF_AUTO_TEMPERATURE,
default=current.get(CONF_AUTO_TEMPERATURE, 21),
): vol.Coerce(float),
vol.Optional(
CONF_AWAY_TEMPERATURE,
default=current.get(CONF_AWAY_TEMPERATURE, 14),
): vol.Coerce(float),
vol.Optional(
CONF_AWAY_DELAY_MINUTES,
default=current.get(CONF_AWAY_DELAY_MINUTES, 5),
): vol.Coerce(int),
vol.Optional(
CONF_INTERRUPTIBLE,
default=current.get(CONF_INTERRUPTIBLE, True),
): cv.boolean,
vol.Optional(
CONF_DEFAULT_OVERRIDE_MODE,
default=current.get(CONF_DEFAULT_OVERRIDE_MODE, "timer"),
): vol.In(["timer", "infinity"]),
vol.Optional(
CONF_DEFAULT_OVERRIDE_DURATION,
default=current.get(CONF_DEFAULT_OVERRIDE_DURATION, 30),
): vol.Coerce(int),
}
)

return self.async_show_form(
step_id="init",
data_schema=schema,
)
36 changes: 36 additions & 0 deletions custom_components/smart_climate/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,47 @@
"default_override_mode": "Override mode used when adjusting temperature (timer or infinity)",
"default_override_duration": "Default duration in minutes for timer override mode"
}
},
"reconfigure": {
"title": "Reconfigure Smart Climate",
"description": "Change the linked climate entity and home zone",
"data": {
"wrapped_climate": "Wrapped Climate Entity",
"zone_home": "Home Zone"
},
"data_description": {
"wrapped_climate": "The climate entity to wrap and control",
"zone_home": "The zone entity used for presence detection"
}
}
},
"error": {},
"abort": {
"already_configured": "Device is already configured"
}
},
"options": {
"step": {
"init": {
"title": "Smart Climate Options",
"description": "Adjust temperature and override settings",
"data": {
"auto_temperature": "Home Temperature",
"away_temperature": "Away Temperature",
"away_delay_minutes": "Away Delay (minutes)",
"interruptible": "Override is interruptible",
"default_override_mode": "Default Override Mode",
"default_override_duration": "Default Override Duration (minutes)"
},
"data_description": {
"auto_temperature": "Target temperature when somebody is home",
"away_temperature": "Target temperature when nobody is home",
"away_delay_minutes": "Minutes to wait before applying the away temperature",
"interruptible": "Whether a presence change can interrupt an active override",
"default_override_mode": "Override mode used when adjusting temperature (timer or infinity)",
"default_override_duration": "Default duration in minutes for timer override mode"
}
}
}
}
}
36 changes: 36 additions & 0 deletions custom_components/smart_climate/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,47 @@
"default_override_mode": "Override mode used when adjusting temperature (timer or infinity)",
"default_override_duration": "Default duration in minutes for timer override mode"
}
},
"reconfigure": {
"title": "Reconfigure Smart Climate",
"description": "Change the linked climate entity and home zone",
"data": {
"wrapped_climate": "Wrapped Climate Entity",
"zone_home": "Home Zone"
},
"data_description": {
"wrapped_climate": "The climate entity to wrap and control",
"zone_home": "The zone entity used for presence detection"
}
}
},
"error": {},
"abort": {
"already_configured": "Device is already configured"
}
},
"options": {
"step": {
"init": {
"title": "Smart Climate Options",
"description": "Adjust temperature and override settings",
"data": {
"auto_temperature": "Home Temperature",
"away_temperature": "Away Temperature",
"away_delay_minutes": "Away Delay (minutes)",
"interruptible": "Override is interruptible",
"default_override_mode": "Default Override Mode",
"default_override_duration": "Default Override Duration (minutes)"
},
"data_description": {
"auto_temperature": "Target temperature when somebody is home",
"away_temperature": "Target temperature when nobody is home",
"away_delay_minutes": "Minutes to wait before applying the away temperature",
"interruptible": "Whether a presence change can interrupt an active override",
"default_override_mode": "Override mode used when adjusting temperature (timer or infinity)",
"default_override_duration": "Default duration in minutes for timer override mode"
}
}
}
}
}
36 changes: 36 additions & 0 deletions custom_components/smart_climate/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,47 @@
"default_override_mode": "Overschrijfmodus bij het aanpassen van de temperatuur (timer of oneindig)",
"default_override_duration": "Standaardduur in minuten voor timer-overschrijfmodus"
}
},
"reconfigure": {
"title": "Smart Climate Herconfigureren",
"description": "Wijzig het gekoppelde klimaatapparaat en de thuiszone",
"data": {
"wrapped_climate": "Gekoppeld Klimaatapparaat",
"zone_home": "Thuiszone"
},
"data_description": {
"wrapped_climate": "Het klimaatapparaat om te beheren",
"zone_home": "De zone die gebruikt wordt voor aanwezigheidsdetectie"
}
}
},
"error": {},
"abort": {
"already_configured": "Apparaat is al geconfigureerd"
}
},
"options": {
"step": {
"init": {
"title": "Smart Climate Opties",
"description": "Pas temperatuur- en overschrijfinstellingen aan",
"data": {
"auto_temperature": "Thuis Temperatuur",
"away_temperature": "Weg Temperatuur",
"away_delay_minutes": "Vertrekvertraging (minuten)",
"interruptible": "Overschrijving is onderbrekbaar",
"default_override_mode": "Standaard Overschrijfmodus",
"default_override_duration": "Standaard Overschrijfduur (minuten)"
},
"data_description": {
"auto_temperature": "Doeltemperatuur wanneer iemand thuis is",
"away_temperature": "Doeltemperatuur wanneer niemand thuis is",
"away_delay_minutes": "Minuten te wachten voordat de weg-temperatuur wordt toegepast",
"interruptible": "Of een aanwezigheidswijziging een actieve overschrijving kan onderbreken",
"default_override_mode": "Overschrijfmodus bij het aanpassen van de temperatuur (timer of oneindig)",
"default_override_duration": "Standaardduur in minuten voor timer-overschrijfmodus"
}
}
}
}
}