Skip to content

Commit 15f909d

Browse files
Merge pull request #3 from BottlecapDave/develop
Next release
2 parents 40c4163 + 08d674a commit 15f909d

File tree

20 files changed

+219
-161
lines changed

20 files changed

+219
-161
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ body:
5959
id: ha-logs
6060
attributes:
6161
label: Home Assistant Logs
62-
description: Paste any related Home Assistant logs here. Please follow the instructions as outlined in the [FAQ](https://bottlecapdave.github.io/homeassistant-targettimeframes/faq#how-do-i-increase-the-logs-for-the-integration)
62+
description: Paste any related Home Assistant logs here. Please follow the instructions as outlined in the [FAQ](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/faq#how-do-i-increase-the-logs-for-the-integration)
6363
validations:
6464
required: true
6565
- type: checkboxes
6666
id: confirm
6767
attributes:
6868
label: Confirmation
6969
options:
70-
- label: I confirm that I cannot find my solution within the [documentation](https://bottlecapdave.github.io/homeassistant-targettimeframes)
70+
- label: I confirm that I cannot find my solution within the [documentation](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes)
7171
required: true
72-
- label: I confirm that I cannot find my solution within the [FAQ](https://bottlecapdave.github.io/homeassistant-targettimeframes/faq)
72+
- label: I confirm that I cannot find my solution within the [FAQ](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/faq)
7373
required: true

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ body:
3030
attributes:
3131
label: Confirmation
3232
options:
33-
- label: By submitting this feature request, you agree that you have read the [documentation](https://bottlecapdave.github.io/homeassistant-targettimeframes) and confirmed it does not already exist
33+
- label: By submitting this feature request, you agree that you have read the [documentation](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes) and confirmed it does not already exist
3434
required: true
3535
- label: I am willing/able to help contribute to the solution of this feature

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ To install, place the contents of `custom_components` into the `<config director
2929

3030
## How to setup
3131

32-
You will initially need to setup one or more [data sources](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/setup/data_source.md). You'll then need to setup one or more [target timeframe](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/setup/target_timeframe.md) or [rolling target timeframe](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/setup/rolling_target_timeframe.md) sensors.
32+
You will initially need to setup one or more [data sources](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/setup/data_source). You'll then need to setup one or more [target timeframe](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/setup/target_timeframe) or [rolling target timeframe](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/setup/rolling_target_timeframe) sensors.
3333

3434
## Events
3535

36-
This integration raises several events, which can be used for various tasks like automations. For more information, please see the [events docs](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/events.md).
36+
This integration raises several events, which can be used for various tasks like automations. For more information, please see the [events docs](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/events).
3737

3838
## Services
3939

40-
This integration includes several services. Please review them in the [services doc](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/services.md).
40+
This integration includes several services. Please review them in the [services doc](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/services).
4141

4242
## Blueprints
4343

44-
A selection of [blueprints](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/blueprints.md) are available to help get you up and running quickly with the integration.
44+
A selection of [blueprints](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/blueprints) are available to help get you up and running quickly with the integration.
4545

4646
## FAQ
4747

48-
Before raising anything, please read through the [faq](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/faq.md). If you have questions, then you can raise a [discussion](https://github.com/BottlecapDave/homeassistant-targettimeframes/discussions). If you have found a bug or have a feature request please [raise it](https://github.com/BottlecapDave/homeassistant-targettimeframes/issues) using the appropriate report template.
48+
Before raising anything, please read through the [faq](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/faq). If you have questions, then you can raise a [discussion](https://github.com/BottlecapDave/homeassistant-targettimeframes/discussions). If you have found a bug or have a feature request please [raise it](https://github.com/BottlecapDave/homeassistant-targettimeframes/issues) using the appropriate report template.
4949

5050
## Sponsorship
5151

52-
Please see the [sponsorship](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/sponsorship.md) page for more information.
52+
Please see the [sponsorship](https://bottlecapdave.github.io/HomeAssistant-TargetTimeframes/sponsorship) page for more information.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Repairs - Invalid Target Timeframe
2+
3+
If you receive this error, it means that one or more of your target timeframe sensors have gone into an invalid state. This can happen if more validation has been added, which your target timeframe sensor(s) are in violation of.
4+
5+
To solve this
6+
7+
1. Go to [your integration](https://my.home-assistant.io/redirect/integration/?domain=target_timeframes)
8+
2. Click configure against the target timeframe sensor that is in violation
9+
3. Update the config and save your changes
10+
11+
If you are still having issues, feel free to raise a discussion.

_docs/services.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ The structure of the data should match the following
2525
// Any additional metadata that might describe how the value was created
2626
}
2727
},
28+
{
29+
"start": "2025-01-01T00:30:00Z",
30+
"end": "2025-01-01T01:00:00Z",
31+
"value": 0.2,
32+
"metadata": {
33+
// Any additional metadata that might describe how the value was created
34+
}
35+
},
2836
...
2937
]
3038
```
3139

40+
Each item within the data must be in thirty minute increments. The minute must be 00 or 30, the second should be zero.
41+
3242
#### Automations
3343

3444
Examples can be found in the [blueprints](./blueprints.md) section for configuring a variety of different data sources.
@@ -94,7 +104,7 @@ actions:
94104
- action: target_timeframes.update_target_timeframe_config
95105
data:
96106
target_hours: >
97-
"{{ states('input_number.target_timeframes_target_hours') | string }}"
107+
{{ states('input_number.target_timeframes_target_hours') }}
98108
target_start_time: >
99109
{{ states('input_text.target_timeframes_target_from') }}
100110
target_end_time: >
@@ -161,9 +171,9 @@ actions:
161171
- action: target_timeframes.update_target_timeframe_config
162172
data:
163173
target_hours: >
164-
"{{ states('input_number.target_timeframes_target_hours') | string }}"
174+
{{ states('input_number.target_timeframes_target_hours') }}
165175
target_look_ahead_hours: >
166-
"{{ states('input_number.target_timeframes_rolling_target_look_ahead_hours') | string }}"
176+
{{ states('input_number.target_timeframes_rolling_target_look_ahead_hours') }}
167177
target_offset: >
168178
{{ states('input_text.target_timeframes_target_offset') }}
169179
target:

_docs/setup/rolling_target_timeframe.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Rolling Target timeframe Sensor(s)
1+
# Rolling Target Timeframe Sensor(s)
22

3-
After you've configured your [data source](./data_source.md), you'll be able to configure rolling target timeframe sensors. These are configured as sub configuration options associated with your data source. Select `Rolling Target timeframe` from the sub menu.
3+
After you've configured your [data source](./data_source.md), you'll be able to configure rolling target timeframe sensors. These are configured as sub configuration options associated with your data source. Select `Rolling Target Timeframe` from the sub menu.
44

55
These sensors calculate the lowest continuous or intermittent values within the next available `x` hours, where `x` is configurable via the sensor, and turn on when these periods are active. If you are targeting an export meter, then the sensors will calculate the highest continuous or intermittent values within the next available `x` hours and turn on when these periods are active. If you are wanting to evaluate on a fixed basis (e.g. every 24 hours), you might be interested in the [standard target timeframe sensors](./target_timeframe.md)
66

77
These sensors can then be used in automations to turn on/off devices that save you (and the planet) energy and money. You can go through this flow as many times as you need rolling target timeframe sensors.
88

9-
Each sensor will be in the form `binary_sensor.target_timeframes_{{DATA_SOURCE_ID}}_{{TARGET_RATE_NAME}}`.
9+
Each sensor will be in the form `binary_sensor.target_timeframes_{{DATA_SOURCE_ID}}_{{TARGET_TIMEFRAME_NAME}}`.
1010

1111
## Setup
1212

_docs/setup/target_timeframe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Target Rate Sensor(s)
1+
# Target Timeframe Sensor(s)
22

33
After you've configured your [data source](./data_source.md), you'll be able to configure rolling target timeframe sensors. These are configured as sub configuration options associated with your data source. Select `Target timeframe` from the sub menu.
44

55
These sensors calculate the lowest continuous or intermittent values **within a 24 hour period** and turn on when these periods are active. If you are targeting an export meter, then the sensors will calculate the highest continuous or intermittent values **within a 24 hour period** and turn on when these periods are active. If you are wanting to evaluate on a rolling basis, you might be interested in the [rolling target value sensors](./rolling_target_timeframe.md)
66

77
These sensors can then be used in automations to turn on/off devices that save you (and the planet) energy and money. You can go through this flow as many times as you need target value sensors.
88

9-
Each sensor will be in the form `binary_sensor.target_timeframes_{{DATA_SOURCE_ID}}_{{TARGET_RATE_NAME}}`.
9+
Each sensor will be in the form `binary_sensor.target_timeframes_{{DATA_SOURCE_ID}}_{{TARGET_TIMEFRAME_NAME}}`.
1010

1111
## Setup
1212

custom_components/target_timeframes/binary_sensor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ async def async_setup_entry(hass, entry, async_add_entities):
5050
vol.All(
5151
cv.make_entity_service_schema(
5252
{
53-
vol.Optional("target_hours"): str,
53+
vol.Optional("target_hours"): vol.Coerce(float),
5454
vol.Optional("target_start_time"): str,
5555
vol.Optional("target_end_time"): str,
5656
vol.Optional("target_offset"): str,
57-
vol.Optional("target_minimum_value"): str,
58-
vol.Optional("target_maximum_value"): str,
57+
vol.Optional("target_minimum_value"): vol.Coerce(float),
58+
vol.Optional("target_maximum_value"): vol.Coerce(float),
5959
vol.Optional("target_weighting"): str,
6060
vol.Optional("persist_changes"): bool,
6161
},
@@ -65,19 +65,19 @@ async def async_setup_entry(hass, entry, async_add_entities):
6565
"target_hours", "target_start_time", "target_end_time", "target_offset", "target_minimum_value", "target_maximum_value"
6666
),
6767
),
68-
"async_update_target_rate_config",
68+
"async_update_target_timeframe_config",
6969
)
7070
else:
7171
platform.async_register_entity_service(
7272
"update_rolling_target_timeframe_config",
7373
vol.All(
7474
cv.make_entity_service_schema(
7575
{
76-
vol.Optional("target_hours"): str,
77-
vol.Optional("target_look_ahead_hours"): str,
76+
vol.Optional("target_hours"): vol.Coerce(float),
77+
vol.Optional("target_look_ahead_hours"): vol.Coerce(float),
7878
vol.Optional("target_offset"): str,
79-
vol.Optional("target_minimum_value"): str,
80-
vol.Optional("target_maximum_value"): str,
79+
vol.Optional("target_minimum_value"): vol.Coerce(float),
80+
vol.Optional("target_maximum_value"): vol.Coerce(float),
8181
vol.Optional("target_weighting"): str,
8282
vol.Optional("persist_changes"): bool,
8383
},
@@ -87,7 +87,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
8787
"target_hours", "target_look_ahead_hours", "target_offset", "target_minimum_value", "target_maximum_value"
8888
),
8989
),
90-
"async_update_rolling_target_rate_config",
90+
"async_update_rolling_target_timeframe_config",
9191
)
9292

9393
async_add_entities(entities, config_subentry_id=sub_entry_id)

custom_components/target_timeframes/config/rolling_target_timeframe.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ async def async_migrate_rolling_target_timeframe_config(version: int, data: {},
2626

2727
return new_data
2828

29-
def merge_rolling_target_rate_config(data: dict, options: dict, updated_config: dict = None):
29+
def merge_rolling_target_timeframe_config(data: dict, updated_config: dict = None):
3030
config = dict(data)
31-
if options is not None:
32-
config.update(options)
3331

3432
if updated_config is not None:
3533
config.update(updated_config)

custom_components/target_timeframes/config/target_timeframe.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,30 @@ async def async_migrate_target_timeframe_config(version: int, data: {}, get_entr
3232

3333
return new_data
3434

35-
def merge_target_timeframe_config(data: dict, options: dict, updated_config: dict = None):
35+
def merge_target_timeframe_config(data: dict, updated_config: dict = None):
3636
config = dict(data)
37-
if options is not None:
38-
config.update(options)
3937

4038
if updated_config is not None:
4139
config.update(updated_config)
4240

41+
if CONFIG_TARGET_START_TIME not in updated_config and CONFIG_TARGET_START_TIME in config:
42+
config[CONFIG_TARGET_START_TIME] = None
43+
44+
if CONFIG_TARGET_END_TIME not in updated_config and CONFIG_TARGET_END_TIME in config:
45+
config[CONFIG_TARGET_END_TIME] = None
46+
47+
if CONFIG_TARGET_OFFSET not in updated_config and CONFIG_TARGET_OFFSET in config:
48+
config[CONFIG_TARGET_OFFSET] = None
49+
50+
if CONFIG_TARGET_MIN_VALUE not in updated_config and CONFIG_TARGET_MIN_VALUE in config:
51+
config[CONFIG_TARGET_MIN_VALUE] = None
52+
53+
if CONFIG_TARGET_MAX_VALUE not in updated_config and CONFIG_TARGET_MAX_VALUE in config:
54+
config[CONFIG_TARGET_MAX_VALUE] = None
55+
56+
if CONFIG_TARGET_WEIGHTING not in updated_config and CONFIG_TARGET_WEIGHTING in config:
57+
config[CONFIG_TARGET_WEIGHTING] = None
58+
4359
return config
4460

4561
def is_time_frame_long_enough(hours, start_time, end_time):
@@ -54,7 +70,7 @@ def is_time_frame_long_enough(hours, start_time, end_time):
5470

5571
return available_minutes >= target_minutes
5672

57-
def validate_target_rate_config(data):
73+
def validate_target_timeframe_config(data):
5874
errors = {}
5975

6076
matches = re.search(REGEX_ENTITY_NAME, data[CONFIG_TARGET_NAME])

0 commit comments

Comments
 (0)