Skip to content

Commit

Permalink
v2024.4.1 fixes #328
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenterheerdt committed Apr 1, 2024
1 parent 5ef7873 commit 0ac6b5c
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 6 deletions.
72 changes: 71 additions & 1 deletion custom_components/smart_irrigation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,18 @@ async def async_update_zone_config(self, zone_id: int = None, data: dict = {}):
elif const.ATTR_UPDATE_ALL in data:
_LOGGER.info("Updating all zones.")
await self._async_update_all()
elif const.ATTR_SET_MULTIPLIER in data:
# set a multiplier to a new vlue
new_multiplier_value = 0
if const.ATTR_NEW_MULTIPLIER_VALUE in data:
new_multiplier_value = data[const.ATTR_NEW_MULTIPLIER_VALUE]
res = self.store.async_get_zone(zone_id)
if not res:
return
data[const.ZONE_MULTIPLIER] = new_multiplier_value
data.pop(const.ATTR_SET_MULTIPLIER)
self.store.async_update_zone(zone_id, data)
async_dispatcher_send(self.hass, const.DOMAIN + "_config_updated", zone_id)
elif const.ATTR_SET_BUCKET in data:
# set a bucket to a new value
new_bucket_value = 0
Expand Down Expand Up @@ -1448,6 +1460,18 @@ async def _async_set_all_buckets(self, val=0):
zone_id=zone.get(const.ZONE_ID), data=data
)

async def _async_set_all_multipliers(self, val=0):
"""Sets all multipliers to val"""
zones = self.store.async_get_zones()
data = {}
data[const.ATTR_SET_MULTIPLIER] = {}
data[const.ATTR_NEW_MULTIPLIER_VALUE] = val

for zone in zones:
await self.async_update_zone_config(
zone_id=zone.get(const.ZONE_ID), data=data
)

async def handle_calculate_all_zones(self, call):
"""Calculate all zones."""
_LOGGER.info("Calculate all zones service called.")
Expand Down Expand Up @@ -1546,10 +1570,46 @@ async def handle_set_all_buckets(self, call):
if const.ATTR_NEW_BUCKET_VALUE in call.data:
new_value = call.data[const.ATTR_NEW_BUCKET_VALUE]
_LOGGER.info(
"Reset all buckets service called, new value: {}".format(new_value)
"Set all buckets service called, new value: {}".format(new_value)
)
await self._async_set_all_buckets(new_value)

async def handle_set_multiplier(self, call):
"""Reset a specific zone multiplier to new value"""
if (
const.SERVICE_ENTITY_ID in call.data
and const.ATTR_NEW_MULTIPLIER_VALUE in call.data
):
new_value = call.data[const.ATTR_NEW_MULTIPLIER_VALUE]
eid = call.data[const.SERVICE_ENTITY_ID]
if not isinstance(eid, list):
eid = [call.data[const.SERVICE_ENTITY_ID]]
for entity in eid:
_LOGGER.info(
"Set multiplier service called for zone {}, new value: {}.".format(
entity, new_value
)
)
# find entity zone id and call calculate on the zone
state = self.hass.states.get(entity)
if state:
# find zone_id for zone with name
zone_id = state.attributes.get(const.ZONE_ID)
if not zone_id is None:
data = {}
data[const.ATTR_SET_MULTIPLIER] = {}
data[const.ATTR_NEW_MULTIPLIER_VALUE] = new_value
await self.async_update_zone_config(zone_id=zone_id, data=data)

async def handle_set_all_multipliers(self, call):
"""Reset all multipliers to new value"""
if const.ATTR_NEW_MULTIPLIER_VALUE in call.data:
new_value = call.data[const.ATTR_NEW_MULTIPLIER_VALUE]
_LOGGER.info(
"Set all multipliers service called, new value: {}".format(new_value)
)
await self._async_set_all_multipliers(new_value)

async def handle_clear_weatherdata(self, call):
"""Clear all collected weatherdata"""
await self._async_clear_all_weatherdata()
Expand Down Expand Up @@ -1601,3 +1661,13 @@ def register_services(hass):
const.SERVICE_CLEAR_WEATHERDATA,
coordinator.handle_clear_weatherdata,
)

hass.services.async_register(
const.DOMAIN,
const.SERVICE_SET_ALL_MULTIPLIERS,
coordinator.handle_set_all_multipliers,
)

hass.services.async_register(
const.DOMAIN, const.SERVICE_SET_MULTIPLIER, coordinator.handle_set_multiplier
)
6 changes: 5 additions & 1 deletion custom_components/smart_irrigation/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Store constants."""


VERSION = "v2024.4.0"
VERSION = "v2024.4.1"
NAME = "Smart Irrigation"
MANUFACTURER = "@jeroenterheerdt"

Expand Down Expand Up @@ -78,6 +78,8 @@
ATTR_CALCULATE_ALL = "calculate_all"
ATTR_SET_BUCKET = "set_bucket"
ATTR_NEW_BUCKET_VALUE = "new_bucket_value"
ATTR_SET_MULTIPLIER = "set_multiplier"
ATTR_NEW_MULTIPLIER_VALUE = "new_multiplier_value"
ATTR_UPDATE = "update"
ATTR_UPDATE_ALL = "update_all"
ATTR_OVERRIDE_CACHE = "override_cache"
Expand Down Expand Up @@ -237,5 +239,7 @@
SERVICE_RESET_ALL_BUCKETS = "reset_all_buckets"
SERVICE_SET_BUCKET = "set_bucket"
SERVICE_SET_ALL_BUCKETS = "set_all_buckets"
SERVICE_SET_MULTIPLIER = "set_multiplier"
SERVICE_SET_ALL_MULTIPLIERS = "set_all_multipliers"
SERVICE_ENTITY_ID = "entity_id"
SERVICE_CLEAR_WEATHERDATA = "clear_all_weather_data"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 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.4.0";
export const VERSION = "v2024.4.1";
export const REPO = "https://github.com/jeroenterheerdt/HASmartIrrigation;";
export const ISSUES_URL = REPO + "/issues";

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.4.0"
"version": "v2024.4.1"
}
17 changes: 16 additions & 1 deletion custom_components/smart_irrigation/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ reset_bucket:
entity:
domain: sensor
reset_all_buckets:
clear_all_weather_data:
clear_all_weather_data:
set_all_multipliers:
fields:
new_multiplier_value:
required: true
example: 1.0
default: 1.0
set_multiplier:
target:
entity:
domain: sensor
fields:
new_multiplier_value:
required: true
example: 1.0
default: 1.0
5 changes: 5 additions & 0 deletions custom_components/smart_irrigation/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .const import (
ATTR_NEW_BUCKET_VALUE,
ATTR_NEW_MULTIPLIER_VALUE,
CONF_AUTO_CALC_ENABLED,
CONF_AUTO_CLEAR_ENABLED,
CONF_AUTO_UPDATE_DELAY,
Expand Down Expand Up @@ -498,6 +499,10 @@ def async_update_zone(self, zone_id: int, changes: dict) -> ZoneEntry:
zone_id = int(zone_id)
old = self.zones[zone_id]
if changes:
# handle multiplier value change
if ATTR_NEW_MULTIPLIER_VALUE in changes:
changes[ZONE_MULTIPLIER] = changes[ATTR_NEW_MULTIPLIER_VALUE]
changes.pop(ATTR_NEW_MULTIPLIER_VALUE)
# handle bucket value change
if ATTR_NEW_BUCKET_VALUE in changes:
changes[ZONE_BUCKET] = changes[ATTR_NEW_BUCKET_VALUE]
Expand Down
24 changes: 24 additions & 0 deletions custom_components/smart_irrigation/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@
"clear_all_weather_data": {
"name": "Clear all weather data",
"description": "Clear weather data for all zones"
},
"set_multiplier": {
"name": "Set multiplier",
"description": "Set multiplier for a zone to a specific value",
"fields": {
"entity": {
"name": "Entity",
"description": "Zone to set multiplier for"
},
"new_multiplier_value": {
"name": "New multiplier value",
"description": "new value of the multiplier"
}
}
},
"set_all_multipliers": {
"name": "Set all multipliers",
"description": "Set multipliers for all zones to a specific value",
"fields": {
"new_multiplier_value": {
"name": "New multiplier value",
"description": "new value of the multiplier"
}
}
}
}
}

0 comments on commit 0ac6b5c

Please sign in to comment.