diff --git a/custom_components/smart_irrigation/__init__.py b/custom_components/smart_irrigation/__init__.py index e5e2adbc..1c71e072 100644 --- a/custom_components/smart_irrigation/__init__.py +++ b/custom_components/smart_irrigation/__init__.py @@ -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 @@ -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.") @@ -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() @@ -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 + ) diff --git a/custom_components/smart_irrigation/const.py b/custom_components/smart_irrigation/const.py index 4c4cfbe2..a9ca7052 100644 --- a/custom_components/smart_irrigation/const.py +++ b/custom_components/smart_irrigation/const.py @@ -1,7 +1,7 @@ """Store constants.""" -VERSION = "v2024.4.0" +VERSION = "v2024.4.1" NAME = "Smart Irrigation" MANUFACTURER = "@jeroenterheerdt" @@ -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" @@ -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" diff --git a/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js b/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js index b0354433..a337f16a 100644 --- a/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js +++ b/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js @@ -1057,7 +1057,7 @@ a.version="2.29.4",i(Wa),a.fn=us,a.min=Xa,a.max=Ja,a.now=Qa,a.utc=p,a.unix=cs,a. .narrow=${this.narrow} >
${hi("title",this.hass.language)}
-
${"v2024.4.0"}
+
${"v2024.4.1"}
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] diff --git a/custom_components/smart_irrigation/translations/en.json b/custom_components/smart_irrigation/translations/en.json index da1e08c2..100ca33a 100644 --- a/custom_components/smart_irrigation/translations/en.json +++ b/custom_components/smart_irrigation/translations/en.json @@ -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" + } + } } } }