Skip to content

Commit

Permalink
Avoid breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
ollo69 authored and swingerman committed Nov 16, 2022
1 parent be579df commit 82d9e9e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
PRESET_ANTI_FREEZE,
)
}
CONF_PRESETS_OLD = {k: f"{v}_temp" for k, v in CONF_PRESETS.items()}

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -139,6 +140,11 @@
}
).extend({vol.Optional(v): PRESET_SCHEMA for (k, v) in CONF_PRESETS.items()})

# Add the old presets schema to avoid breaking change
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Optional(v): vol.Coerce(float) for (k, v) in CONF_PRESETS_OLD.items()}
)


async def async_setup_platform(
hass: HomeAssistant,
Expand Down Expand Up @@ -184,6 +190,9 @@ async def async_setup_platform(
and ATTR_TARGET_TEMP_HIGH in values
and values[ATTR_TARGET_TEMP_LOW] < values[ATTR_TARGET_TEMP_HIGH]
}
# Try to load presets in old format if new format not available in config
if not presets_dict:
presets = {k: config[v] for k, v in CONF_PRESETS_OLD.items() if v in config}
precision = config.get(CONF_PRECISION)
target_temperature_step = config.get(CONF_TEMP_STEP)
unit = hass.config.units.temperature_unit
Expand Down

0 comments on commit 82d9e9e

Please sign in to comment.