Skip to content

Commit

Permalink
Correct deprecated options warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffy2 committed Mar 17, 2024
1 parent 22ffd78 commit 7e07b39
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
10 changes: 3 additions & 7 deletions custom_components/variable/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Variable implementation for Home Assistant."""

import copy
import json
import logging
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions custom_components/variable/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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: "
Expand Down
53 changes: 28 additions & 25 deletions custom_components/variable/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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"],
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions custom_components/variable/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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: "
Expand Down
4 changes: 1 addition & 3 deletions custom_components/variable/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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: "
Expand Down

0 comments on commit 7e07b39

Please sign in to comment.