diff --git a/custom_components/variable/__init__.py b/custom_components/variable/__init__.py index 9104f92..cd5c988 100644 --- a/custom_components/variable/__init__.py +++ b/custom_components/variable/__init__.py @@ -1,4 +1,5 @@ """Variable implementation for Home Assistant.""" + import copy import json import logging @@ -169,9 +170,8 @@ async def _async_set_legacy_service(call, var_ent): var_fields.setdefault(m, entry.data[m]) var_fields.update({CONF_YAML_PRESENT: True}) # _LOGGER.debug(f"[YAML] Updated var_fields: {var_fields}") - entry.options = {} hass.config_entries.async_update_entry( - entry, data=var_fields, options=entry.options + entry, data=var_fields, options={} ) hass.async_create_task(hass.config_entries.async_reload(entry_id)) @@ -187,7 +187,6 @@ async def _async_set_legacy_service(call, var_ent): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up from a config entry.""" - entry.options = {} # _LOGGER.debug(f"[init async_setup_entry] entry: {entry.data}") if entry.data.get(CONF_YAML_VARIABLE, False) is True: if entry.data.get(CONF_YAML_PRESENT, False) is False: @@ -200,10 +199,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: else: yaml_data = copy.deepcopy(dict(entry.data)) yaml_data.pop(CONF_YAML_PRESENT, None) - entry.options = {} - hass.config_entries.async_update_entry( - entry, data=yaml_data, options=entry.options - ) + hass.config_entries.async_update_entry(entry, data=yaml_data, options={}) hass.data.setdefault(DOMAIN, {}) hass_data = dict(entry.data) diff --git a/custom_components/variable/binary_sensor.py b/custom_components/variable/binary_sensor.py index 72fa8f0..50f2ae4 100644 --- a/custom_components/variable/binary_sensor.py +++ b/custom_components/variable/binary_sensor.py @@ -62,10 +62,8 @@ async def async_setup_entry( config_entry: ConfigEntry, async_add_entities, ) -> None: - """Setup the Binary Sensor Variable entity with a config_entry (config_flow).""" - config_entry.options = {} platform = entity_platform.async_get_current_platform() platform.async_register_entity_service( @@ -224,7 +222,7 @@ async def async_added_to_hass(self): self._hass.config_entries.async_update_entry( self._config_entry, data=self._config, - options=self._config_entry.options, + options={}, ) _LOGGER.debug( f"({self._attr_name}) Updated config_updated: " diff --git a/custom_components/variable/config_flow.py b/custom_components/variable/config_flow.py index b679cea..8f2f4ad 100644 --- a/custom_components/variable/config_flow.py +++ b/custom_components/variable/config_flow.py @@ -1204,12 +1204,11 @@ async def async_step_sensor_options_page_2(self, user_input=None): user_input.pop(k, None) user_input.update({CONF_UPDATED: True}) _LOGGER.debug(f"[Sensor Options Page 2] Final user_input: {user_input}") - self.config_entry.options = {} self.hass.config_entries.async_update_entry( self.config_entry, data=user_input, - options=self.config_entry.options, + options={}, ) await self.hass.config_entries.async_reload(self.config_entry.entry_id) return self.async_create_entry(title="", data=user_input) @@ -1424,14 +1423,14 @@ def build_sensor_options_page_2(self): { vol.Optional( sensor.CONF_STATE_CLASS, - default=self.config_entry.data.get( - sensor.CONF_STATE_CLASS, "None" - ) - if ( - self.config_entry.data.get(CONF_DEVICE_CLASS) - == self.sensor_options_page_1.get(CONF_DEVICE_CLASS) - ) - else "None", + default=( + self.config_entry.data.get(sensor.CONF_STATE_CLASS, "None") + if ( + self.config_entry.data.get(CONF_DEVICE_CLASS) + == self.sensor_options_page_1.get(CONF_DEVICE_CLASS) + ) + else "None" + ), ): selector.SelectSelector( selector.SelectSelectorConfig( options=SENSOR_STATE_CLASS_SELECT_LIST, @@ -1450,14 +1449,14 @@ def build_sensor_options_page_2(self): { vol.Optional( CONF_UNIT_OF_MEASUREMENT, - default=self.config_entry.data.get( - CONF_UNIT_OF_MEASUREMENT, "None" - ) - if ( - self.config_entry.data.get(CONF_DEVICE_CLASS) - == self.sensor_options_page_1.get(CONF_DEVICE_CLASS) - ) - else "None", + default=( + self.config_entry.data.get(CONF_UNIT_OF_MEASUREMENT, "None") + if ( + self.config_entry.data.get(CONF_DEVICE_CLASS) + == self.sensor_options_page_1.get(CONF_DEVICE_CLASS) + ) + else "None" + ), ): selector.SelectSelector( selector.SelectSelectorConfig( options=SENSOR_UNITS_SELECT_LIST, @@ -1483,10 +1482,11 @@ async def async_step_binary_sensor_options( user_input.setdefault(m, self.config_entry.data[m]) user_input.update({CONF_UPDATED: True}) _LOGGER.debug(f"[Binary Sensor Options] updated user_input: {user_input}") - self.config_entry.options = {} self.hass.config_entries.async_update_entry( - self.config_entry, data=user_input, options=self.config_entry.options + self.config_entry, + data=user_input, + options={}, ) await self.hass.config_entries.async_reload(self.config_entry.entry_id) return self.async_create_entry(title="", data=user_input) @@ -1495,9 +1495,11 @@ async def async_step_binary_sensor_options( { vol.Optional( CONF_VALUE, - default=self.config_entry.data.get(CONF_VALUE) - if self.config_entry.data.get(CONF_VALUE) is not None - else "None", + default=( + self.config_entry.data.get(CONF_VALUE) + if self.config_entry.data.get(CONF_VALUE) is not None + else "None" + ), ): selector.SelectSelector( selector.SelectSelectorConfig( options=["None", "true", "false"], @@ -1566,10 +1568,11 @@ async def async_step_device_tracker_options( user_input.setdefault(m, self.config_entry.data[m]) user_input.update({CONF_UPDATED: True}) _LOGGER.debug(f"[Device Tracker Options] updated user_input: {user_input}") - self.config_entry.options = {} self.hass.config_entries.async_update_entry( - self.config_entry, data=user_input, options=self.config_entry.options + self.config_entry, + data=user_input, + options={}, ) await self.hass.config_entries.async_reload(self.config_entry.entry_id) return self.async_create_entry(title="", data=user_input) diff --git a/custom_components/variable/device_tracker.py b/custom_components/variable/device_tracker.py index 500898d..670798d 100644 --- a/custom_components/variable/device_tracker.py +++ b/custom_components/variable/device_tracker.py @@ -76,7 +76,6 @@ async def async_setup_entry( ) -> None: """Setup the Device Tracker Variable entity with a config_entry (config_flow).""" - config_entry.options = {} platform = entity_platform.async_get_current_platform() platform.async_register_entity_service( @@ -201,7 +200,7 @@ async def async_added_to_hass(self): self._hass.config_entries.async_update_entry( self._config_entry, data=self._config, - options=self._config_entry.options, + options={}, ) _LOGGER.debug( f"({self._attr_name}) Updated config_updated: " diff --git a/custom_components/variable/sensor.py b/custom_components/variable/sensor.py index 0c2e0b9..ba99dd9 100644 --- a/custom_components/variable/sensor.py +++ b/custom_components/variable/sensor.py @@ -87,10 +87,8 @@ async def async_setup_entry( config_entry: ConfigEntry, async_add_entities, ) -> None: - """Setup the Sensor Variable entity with a config_entry (config_flow).""" - config_entry.options = {} platform = entity_platform.async_get_current_platform() platform.async_register_entity_service( @@ -245,7 +243,7 @@ async def async_added_to_hass(self): self._hass.config_entries.async_update_entry( self._config_entry, data=self._config, - options=self._config_entry.options, + options={}, ) _LOGGER.debug( f"({self._attr_name}) Updated config_updated: "