Skip to content

Commit 848b03c

Browse files
committed
chore: Fixed reconfiguring target timeframe sensors
1 parent 141ee08 commit 848b03c

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

custom_components/target_timeframes/binary_sensor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
3636
config = dict(sub_entry.data)
3737

3838
if config[CONFIG_KIND] == CONFIG_KIND_TARGET_RATE or config[CONFIG_KIND] == CONFIG_KIND_ROLLING_TARGET_RATE:
39-
await async_setup_target_sensors(hass, entry, config, data_source_id, async_add_entities, data_dict)
39+
await async_setup_target_sensors(hass, entry, sub_entry, config, data_source_id, async_add_entities, data_dict)
4040

4141
platform = entity_platform.async_get_current_platform()
4242

@@ -88,13 +88,13 @@ async def async_setup_entry(hass, entry, async_add_entities):
8888

8989
return True
9090

91-
async def async_setup_target_sensors(hass, entry, config, data_source_id, async_add_entities, initial_data):
91+
async def async_setup_target_sensors(hass, entry, sub_entry, config, data_source_id, async_add_entities, initial_data):
9292
entities = []
9393

9494
if config[CONFIG_KIND] == CONFIG_KIND_TARGET_RATE:
95-
entities.append(TargetTimeframesTargetRate(hass, data_source_id, entry, config, initial_data))
95+
entities.append(TargetTimeframesTargetRate(hass, data_source_id, entry, sub_entry, config, initial_data))
9696
else:
97-
entities.append(TargetTimeframesRollingTargetRate(hass, data_source_id, entry, config, initial_data))
97+
entities.append(TargetTimeframesRollingTargetRate(hass, data_source_id, entry, sub_entry, config, initial_data))
9898

9999
async_add_entities(entities)
100100
return

custom_components/target_timeframes/config_flow.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None)
6767
step_id="reconfigure",
6868
data_schema=self.add_suggested_values_to_schema(
6969
DATA_SCHEMA_SOURCE,
70-
user_input if user_input is not None else {}
70+
user_input if user_input is not None else self._get_reconfigure_entry().data
7171
),
7272
)
7373

@@ -112,16 +112,17 @@ async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None)
112112
errors = validate_target_rate_config(config) if config is not None else {}
113113

114114
if len(errors) < 1 and user_input is not None:
115-
return self.async_update_reload_and_abort(
115+
return self.async_update_and_abort(
116116
self._get_reconfigure_entry(),
117+
self._get_reconfigure_subentry(),
117118
data_updates=config,
118119
)
119120

120121
return self.async_show_form(
121122
step_id="reconfigure",
122123
data_schema=self.add_suggested_values_to_schema(
123124
DATA_SCHEMA_TARGET_TIME_PERIOD,
124-
user_input if user_input is not None else {}
125+
user_input if user_input is not None else self._get_reconfigure_subentry().data
125126
),
126127
)
127128

@@ -155,15 +156,16 @@ async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None)
155156
errors = validate_rolling_target_timeframe_config(config) if config is not None else {}
156157

157158
if len(errors) < 1 and user_input is not None:
158-
return self.async_update_reload_and_abort(
159+
return self.async_update_and_abort(
159160
self._get_reconfigure_entry(),
161+
self._get_reconfigure_subentry(),
160162
data_updates=config,
161163
)
162164

163165
return self.async_show_form(
164166
step_id="reconfigure",
165167
data_schema=self.add_suggested_values_to_schema(
166168
DATA_SCHEMA_ROLLING_TARGET_TIME_PERIOD,
167-
user_input if user_input is not None else {}
169+
user_input if user_input is not None else self._get_reconfigure_subentry().data
168170
),
169171
)

custom_components/target_timeframes/entities/rolling_target_timeframe.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
class TargetTimeframesRollingTargetRate(BinarySensorEntity, RestoreEntity):
5959
"""Sensor for calculating when a target should be turned on or off."""
6060

61-
def __init__(self, hass: HomeAssistant, data_source_id: str, config_entry, config, initial_data):
61+
def __init__(self, hass: HomeAssistant, data_source_id: str, config_entry, config_subentry, config, initial_data):
6262
"""Init sensor."""
6363

6464
self._state = None
6565
self._config_entry = config_entry
66+
self._config_subentry = config_subentry
6667
self._config = config
6768
self._attributes = self._config.copy()
6869
self._last_evaluated = None
@@ -304,13 +305,11 @@ async def async_update_rolling_target_rate_config(self, target_hours=None, targe
304305

305306
if persist_changes:
306307
updatable_keys = [CONFIG_TARGET_HOURS, CONFIG_ROLLING_TARGET_HOURS_LOOK_AHEAD, CONFIG_TARGET_OFFSET, CONFIG_TARGET_MIN_VALUE, CONFIG_TARGET_MAX_VALUE, CONFIG_TARGET_WEIGHTING]
307-
new_config_data = { **self._config_entry.data }
308+
new_config_data = { **self._config_subentry.data }
308309
new_config_data.update(extract_config(config, updatable_keys))
309-
new_config_options = { **self._config_entry.options }
310-
new_config_options.update(extract_config(config, updatable_keys))
311310

312-
self._hass.config_entries.async_update_entry(
311+
self._hass.config_entries.async_update_subentry(
313312
self._config_entry,
314-
data = new_config_data,
315-
options = new_config_options
313+
self._config_subentry,
314+
data = new_config_data
316315
)

custom_components/target_timeframes/entities/target_timeframe.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@
6161
class TargetTimeframesTargetRate(BinarySensorEntity, RestoreEntity):
6262
"""Sensor for calculating when a target should be turned on or off."""
6363

64-
def __init__(self, hass: HomeAssistant, data_source_id: str, config_entry, config, initial_data):
64+
def __init__(self, hass: HomeAssistant, data_source_id: str, config_entry, config_subentry, config, initial_data):
6565
"""Init sensor."""
6666

6767
self._state = None
6868
self._config_entry = config_entry
69+
self._config_subentry = config_subentry
6970
self._config = config
7071
self._attributes = self._config.copy()
7172
self._last_evaluated = None
@@ -328,13 +329,11 @@ async def async_update_target_rate_config(self, target_start_time=None, target_e
328329

329330
if persist_changes:
330331
updatable_keys = [CONFIG_TARGET_HOURS, CONFIG_TARGET_START_TIME, CONFIG_TARGET_END_TIME, CONFIG_TARGET_OFFSET, CONFIG_TARGET_MIN_VALUE, CONFIG_TARGET_MAX_VALUE, CONFIG_TARGET_WEIGHTING]
331-
new_config_data = { **self._config_entry.data }
332+
new_config_data = { **self._config_subentry.data }
332333
new_config_data.update(extract_config(config, updatable_keys))
333-
new_config_options = { **self._config_entry.options }
334-
new_config_options.update(extract_config(config, updatable_keys))
335334

336-
self._hass.config_entries.async_update_entry(
335+
self._hass.config_entries.async_update_subentry(
337336
self._config_entry,
338-
data = new_config_data,
339-
options = new_config_options
337+
self._config_subentry,
338+
data = new_config_data
340339
)

custom_components/target_timeframes/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
],
1212
"documentation": "https://bottlecapdave.github.io/homeassistant-targettimeframes",
1313
"homekit": {},
14-
"iot_class": "cloud_polling",
14+
"iot_class": "local_polling",
15+
"integration_type": "helper",
1516
"issue_tracker": "https://github.com/BottlecapDave/homeassistant-targettimeframes/issues",
1617
"requirements": [
1718
"pydantic"

logo.png

1.25 MB
Loading

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "targettimeframes",
3-
"version": "1.0.0",
3+
"version": "0.1.0",
44
"description": "Home Assistant integration for interacting with Target Timeframes",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)