Skip to content

Commit

Permalink
Merge pull request #211 from DasBasti/bugfix-nonetype-has-no-attribute
Browse files Browse the repository at this point in the history
Bugfix selects breaking device config_entry
  • Loading branch information
DasBasti authored Dec 23, 2024
2 parents bbd4e23 + 4cd058b commit 5232ed8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 11 additions & 8 deletions custom_components/smarthashtag/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ def set_update_interval(self, key: str, deltatime: timedelta) -> None:

def reset_update_interval(self, key: str):
"""Reset interval for this key to default"""
self.set_update_interval(
key,
timedelta(
seconds=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
),
)
if self.config_entry:
self.set_update_interval(
key,
timedelta(
seconds=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
),
)
else:
LOGGER.warning("Cannot reset update interval due to missing config_entry")
18 changes: 10 additions & 8 deletions custom_components/smarthashtag/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ def __init__(

def _get_level_for_location(self, location: HeatingLocation) -> Literal[0, 1, 2, 3]:
"""Get the heating level for the specified location."""
if "selects" in self.coordinator.config_entry.data:
if (
self.coordinator.config_entry
and "selects" in self.coordinator.config_entry.data
):
level = self.coordinator.config_entry.data["selects"].get(location, 0)
return level
else:
LOGGER.debug("No heating level found for %s", location)
return 0

def select_option(self, option: str, **kwargs):
async def async_select_option(self, option: str, **kwargs):
"""Change the selected option."""

async def _update_config_entry(self, new_data):
self.hass.config_entries.async_update_entry(
self.coordinator.config_entry, data=new_data
)

level: int = HEATING_LEVEL_OPTIONS_MAP[option]
self._vehicle.climate_control.set_heating_level(self._location, level)

Expand All @@ -112,7 +112,9 @@ async def _update_config_entry(self, new_data):
if "selects" not in new_data:
new_data["selects"] = {}
new_data["selects"][self._location] = level
self.hass.add_job(_update_config_entry, self, new_data)
self.hass.config_entries.async_update_entry(
self.coordinator.config_entry, data=new_data
)
LOGGER.debug(f"Setting {self._location} to %s", level)

@property
Expand Down

0 comments on commit 5232ed8

Please sign in to comment.