Skip to content

Commit

Permalink
v2024.10.1 setting default aggregation for current precipitation to '…
Browse files Browse the repository at this point in the history
…Last'. Also, fix #484
  • Loading branch information
jeroenterheerdt committed Oct 17, 2024
1 parent 537a0ee commit cf269e5
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 192 deletions.
3 changes: 2 additions & 1 deletion custom_components/smart_irrigation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
altitudeToPressure,
check_time,
convert_between,
convert_list_to_dict,
convert_mapping_to_metric,
loadModules,
relative_to_absolute_pressure,
Expand Down Expand Up @@ -499,7 +500,7 @@ async def async_sensor_state_changed(
if data_last_entry is None or len(data_last_entry) == 0:
data_last_entry = {}
if isinstance(data_last_entry, list):
data_last_entry = dict(data_last_entry)
data_last_entry = convert_list_to_dict(data_last_entry)
data_last_entry[key] = mapping_data[-1][key]
changes = {
const.MAPPING_DATA: mapping_data,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/smart_irrigation/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Store constants."""

VERSION = "v2024.10.0"
VERSION = "v2024.10.1"
NAME = "Smart Irrigation"
MANUFACTURER = "@jeroenterheerdt"

Expand Down
362 changes: 181 additions & 181 deletions custom_components/smart_irrigation/frontend/dist/smart-irrigation.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion custom_components/smart_irrigation/frontend/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const VERSION = "v2024.10.0";
export const VERSION = "v2024.10.1";
export const REPO = "https://github.com/jeroenterheerdt/HASmartIrrigation;";
export const ISSUES_URL = REPO + "/issues";

Expand Down Expand Up @@ -50,6 +50,7 @@ export const MAPPING_DATA = "data";
export const MAPPING_CONF_AGGREGATE = "aggregate";
export const MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT = "average";
export const MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_PRECIPITATION = "maximum";
export const MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_CURRENT_PRECIPITATION = "last";
//removing this as part of beta12. Temperature is the only thing we want to take and we will apply min and max aggregation on our own.
//export const MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_MAX_TEMP = "maximum";
//export const MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_MIN_TEMP = "minimum";
Expand Down
9 changes: 4 additions & 5 deletions custom_components/smart_irrigation/frontend/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export function output_unit(config, arg0: string): TemplateResult {
case ZONE_DRAINAGE_RATE:
if (config.units == CONF_METRIC) {
return html`${unsafeHTML(UNIT_MMH)}`;
}
else return html`${unsafeHTML(UNIT_INCHH)}`;
} else return html`${unsafeHTML(UNIT_INCHH)}`;
break;
case ZONE_BUCKET:
if (config.units == CONF_METRIC) {
Expand Down Expand Up @@ -107,10 +106,10 @@ export function getOptionsForMappingType(mapping: string) {
case MAPPING_PRECIPITATION:
case MAPPING_EVAPOTRANSPIRATION:
case MAPPING_CURRENT_PRECIPITATION:
//this should be mm or inch
//this should be mm/h or inch/h
return [
{ unit: UNIT_MM, system: CONF_METRIC },
{ unit: UNIT_INCH, system: CONF_IMPERIAL },
{ unit: UNIT_MMH, system: CONF_METRIC },
{ unit: UNIT_INCHH, system: CONF_IMPERIAL },
];
case MAPPING_HUMIDITY:
//return %
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
//MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_MAX_TEMP,
//MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_MIN_TEMP,
MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_PRECIPITATION,
MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_CURRENT_PRECIPITATION,
MAPPING_CONF_SENSOR,
MAPPING_CONF_SOURCE,
MAPPING_CONF_SOURCE_NONE,
Expand Down Expand Up @@ -563,6 +564,9 @@ class SmartIrrigationViewMappings extends SubscribeMixin(LitElement) {
if (value === MAPPING_PRECIPITATION) {
selected = MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_PRECIPITATION;
}
if (value === MAPPING_CURRENT_PRECIPITATION) {
selected = MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_CURRENT_PRECIPITATION;
}
//removing this as part of beta12. Temperature is the only thing we want to take and we will apply min and max aggregation on our own.
//else if (value === MAPPING_MAX_TEMP) {
// selected = MAPPING_CONF_AGGREGATE_OPTIONS_DEFAULT_MAX_TEMP;
Expand Down
14 changes: 14 additions & 0 deletions custom_components/smart_irrigation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ def loadModules(moduleDir=None):
return None


def convert_list_to_dict(lst):
"""Convert list to dict."""
res_dict = {}
for i in range(0, len(lst), 1):
# print(i)
# print(lst[i])
if isinstance(lst[i], str):
if i + 1 >= len(lst) or isinstance(lst[i + 1], str):
res_dict[lst[i]] = None
else:
res_dict[lst[i]] = lst[i + 1]
return res_dict


class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/smart_irrigation/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/jeroenterheerdt/HASmartIrrigation/issues",
"requirements": [],
"version": "v2024.10.0"
"version": "v2024.10.1"
}
4 changes: 2 additions & 2 deletions custom_components/smart_irrigation/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
ZONE_STATE_AUTOMATIC,
ZONE_THROUGHPUT,
)
from .helpers import loadModules
from .helpers import loadModules, convert_list_to_dict
from .localize import localize

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -687,7 +687,7 @@ def async_update_mapping(self, mapping_id: int, changes: dict) -> MappingEntry:
if old is not None:
if old.data_last_entry is not None and len(old.data_last_entry) > 0:
if isinstance(old.data_last_entry, list):
old.data_last_entry = dict(old.data_last_entry)
old.data_last_entry = convert_list_to_dict(old.data_last_entry)
if MAPPING_DATA_LAST_ENTRY not in changes:
changes[MAPPING_DATA_LAST_ENTRY] = {}
for key in old.data_last_entry:
Expand Down

0 comments on commit cf269e5

Please sign in to comment.