Skip to content

Commit

Permalink
V2025.01.03b2
Browse files Browse the repository at this point in the history
- Correct some differences in the entities card yaml export
- add config flow option to enable/disable the production of the yaml export
- correct an issue when removing a configuration, remove the entry from the domain correctly
  • Loading branch information
petergridge authored Jan 9, 2025
1 parent d28fb09 commit 34d5262
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 32 deletions.
10 changes: 8 additions & 2 deletions custom_components/irrigationprogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class IrrigationProgram:
water_max: int
water_step: int
parallel: int
card_yaml: bool


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand Down Expand Up @@ -138,7 +139,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
zone_count = len(config.get(ATTR_ZONES)),
water_max = config.get('water_max',30),
water_step = config.get('water_step',1),
parallel = config.get('parallel',1)
parallel = config.get('parallel',1),
card_yaml = config.get('card_yaml',False)
)

zone_data=[]
Expand Down Expand Up @@ -222,7 +224,11 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
#clean up any related helpers
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
#remove the instance of component
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok

async def async_stop_programs(hass,ignore_program):
'''Stop all running programs.'''
Expand Down
4 changes: 4 additions & 0 deletions custom_components/irrigationprogram/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ async def async_step_advanced(self, user_input=None):
self._data['water_max'] = user_input['water_max']
self._data['water_step'] = user_input['water_step']
self._data['parallel'] = user_input['parallel']
self._data['card_yaml'] = user_input['card_yaml']
return await self.async_step_menu()

if user_input:
Expand All @@ -352,6 +353,7 @@ async def async_step_advanced(self, user_input=None):
vol.Optional('water_max', description={"suggested_value": default_input.get('water_max',30)}): sel.NumberSelector({"min":1, "max":9999, "mode":"box"}),
vol.Optional('water_step', description={"suggested_value": default_input.get('water_step',1)}): sel.NumberSelector({"min":1, "max":100, "mode":"box"}),
vol.Optional('parallel', description={"suggested_value": default_input.get('parallel',1)}): sel.NumberSelector({"min":1, "max":10, "mode":"box"}),
vol.Optional('card_yaml', description={"suggested_value": default_input.get('card_yaml',False)}): cv.boolean,
}
)

Expand Down Expand Up @@ -471,6 +473,7 @@ async def async_step_advanced(self, user_input=None):
newdata['water_max'] = user_input['water_max']
newdata['water_step'] = user_input['water_step']
newdata['parallel'] = user_input['parallel']
newdata['card_yaml'] = user_input['card_yaml']
# Return the form of the next step.
self._data = newdata
if user_input[ATTR_START_TYPE] not in ["sunset"]:
Expand Down Expand Up @@ -501,6 +504,7 @@ async def async_step_advanced(self, user_input=None):
vol.Optional('water_max', description={"suggested_value": default_input.get('water_max',30)}): sel.NumberSelector({"min":1, "max":9999, "mode":"box"}),
vol.Optional('water_step', description={"suggested_value": default_input.get('water_step',1)}): sel.NumberSelector({"min":1, "max":100, "mode":"box"}),
vol.Optional('parallel', description={"suggested_value": default_input.get('parallel',1)}): sel.NumberSelector({"min":1, "max":10, "mode":"box"}),
vol.Optional('card_yaml', description={"suggested_value": default_input.get('card_yaml',1)}): cv.boolean,
}
)
return self.async_show_form(
Expand Down
48 changes: 27 additions & 21 deletions custom_components/irrigationprogram/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ def __init__(

self._localtimezone = ZoneInfo(self._hass.config.time_zone)

# def generate_card (self):
"""Create card config."""
if self._program.card_yaml:
self.generate_card()

def generate_card (self):
"""Create card config yaml."""

def add_entity(object,conditions,simple=False):
if object:
Expand Down Expand Up @@ -131,18 +134,22 @@ def add_entity_2(object,conditions,simple=False):
return data
return ""

card:str = "### Copy into manual card"+chr(10)
card += "```"+chr(10)
card:str = "### Copy into manual card" + chr(10)
card += "```" + chr(10)

card += "state_color: true" + chr(10)
card += "show_header_toggle: false" + chr(10)

card += "type: entities" + chr(10)
card += "entities:" + chr(10)
card += "- type: conditional" + chr(10)
card += " conditions:" + chr(10)
card += " - entity: " + self._device_id + chr(10)
card += " state: off" + chr(10)
card += " row:" + chr(10)
card += " type: buttons" + chr(10)
card += " type: buttons" + chr(10)
card += " entities: " + chr(10)
card += " - entity: " + self._device_id+ chr(10)
card += " - entity: " + self._device_id + chr(10)
card += " show_name: true" + chr(10)
card += " - entity: " + self._program.config.entity_id + chr(10)
card += " show_name: true" + chr(10)
Expand All @@ -151,7 +158,7 @@ def add_entity_2(object,conditions,simple=False):
card += " - entity: " + self._device_id + chr(10)
card += " state: on" + chr(10)
card += " row:" + chr(10)
card += " type: buttons" + chr(10)
card += " type: buttons" + chr(10)
card += " entities: " + chr(10)
card += " - entity: " + self._device_id + chr(10)
card += " show_name: true" + chr(10)
Expand All @@ -160,7 +167,7 @@ def add_entity_2(object,conditions,simple=False):
card += " - entity: " + self._program.pause.entity_id + chr(10)
card += " show_name: true" + chr(10)

condition = [{ "entity": self._program.config.entity_id, "state_not": "on" },{ "entity": "showconfig", "state_not": "on" }]
condition = [{ "entity": self._device_id, "state_not": "on" },{ "entity": self._program.config.entity_id, "state_not": "on" }]
card += add_entity(self._program.start_time,condition,True)

condition = [{ "entity": self._program.config.entity_id, "state": "on" }]
Expand All @@ -186,53 +193,52 @@ def add_entity_2(object,conditions,simple=False):

card += "- type: conditional" + chr(10)
card += " conditions:" + chr(10)
card += " - entity: " + zone.zone + chr(10)
card += " - entity: " + zone.switch.entity_id + chr(10)
card += " state: off" + chr(10)
card += " row:" + chr(10)
card += " type: buttons" + chr(10)
card += " entities: " + chr(10)
card += " - entity: " + zone.zone + chr(10)
card += " - entity: " + zone.switch.entity_id + chr(10)
card += " show_name: true" + chr(10)
card += " show_icon: true" + chr(10)
card += " tap_action: " + chr(10)
card += " action: call-service" + chr(10)
card += " service: switch.toggle" + chr(10)
card += " service_data:" + chr(10)
card += " entity_id: " + zone.zone + chr(10)
card += " entity_id: " + zone.switch.entity_id + chr(10)
card += " - entity: " + zone.config.entity_id + chr(10)
card += " show_name: true" + chr(10)


card += "- type: conditional" + chr(10)
card += " conditions:" + chr(10)
card += " - entity: " + zone.zone + chr(10)
card += " - entity: " + zone.switch.entity_id + chr(10)
card += " state_not: off" + chr(10)
card += " row:" + chr(10)
card += " type: buttons" + chr(10)
card += " entities: " + chr(10)
card += " - entity: " + zone.zone + chr(10)
card += " - entity: " + zone.switch.entity_id + chr(10)
card += " show_name: true" + chr(10)
card += " show_icon: true" + chr(10)
card += " tap_action: " + chr(10)
card += " action: call-service" + chr(10)
card += " service: switch.toggle" + chr(10)
card += " service_data:" + chr(10)
card += " entity_id: " + zone.zone + chr(10)
card += " entity_id: " + zone.switch.entity_id + chr(10)
card += " - entity: " + zone.config.entity_id + chr(10)
card += " show_name: true" + chr(10)
card += " - entity: " + zone.status.entity_id + chr(10)
card += " show_name: false" + chr(10)

condition = [{ "entity": "zonestatus", "state": '["off"]'} ]
condition = [{ "entity": zone.status.entity_id, "state": '["off"]'} ]
card += add_entity(zone.next_run,condition)

condition = [{ "entity": "zonestatus", "state_not": '["off", "on", "pending", "eco"]'} ]
condition = [{ "entity": zone.status.entity_id, "state_not": '["off", "on", "pending", "eco"]'} ]
card += add_entity(zone.status,condition)

condition = [{ "entity": "zonestatus", "state": '["on","eco","pending"]'} ]
card += add_entity(zone.switch,condition)
condition = [{ "entity": zone.status.entity_id, "state": '["on","eco","pending"]'} ]
card += add_entity(zone.remaining_time,condition)

condition = [{ "entity": "zonestatus", "state_not": '["on", "eco", "pending"]' },{ "entity": zone.config.entity_id, "state": "on" }]
condition = [{ "entity": zone.status.entity_id, "state_not": '["on", "eco", "pending"]' },{ "entity": zone.config.entity_id, "state": "on" }]
card += add_entity(zone.last_ran,condition)

condition = [{ "entity": zone.config.entity_id, "state": "on" }]
Expand All @@ -251,7 +257,7 @@ def add_entity_2(object,conditions,simple=False):

#create the persistent notification
async_create(
hass,
self._hass,
message=card,
title="Irrigation Controller"
)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/irrigationprogram/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"rain_behaviour": "Rain sensor behaviour",
"water_max": "Maximum watering time/volume",
"water_step": "Time/volume step",
"parallel": "Zone parallel execution"
"parallel": "Zone parallel execution",
"card_yaml": "Enable creation of entities card yaml"
}
}
}
Expand Down Expand Up @@ -228,7 +229,8 @@
"rain_behaviour": "Rain sensor behaviour",
"water_max": "Maximum watering time/volume",
"water_step": "Time/volume step",
"parallel": "Zone parallel execution"
"parallel": "Zone parallel execution",
"card_yaml": "Enable creation of entities card yaml"
}
},
"update_program": {
Expand Down
6 changes: 4 additions & 2 deletions custom_components/irrigationprogram/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"rain_behaviour": "Rain sensor behaviour",
"water_max": "Maximum watering time/volume",
"water_step": "Time/volume step",
"parallel": "Zone parallel execution"
"parallel": "Zone parallel execution",
"card_yaml": "Enable creation of entities card yaml"
}
}
}
Expand Down Expand Up @@ -228,7 +229,8 @@
"rain_behaviour": "Rain sensor behaviour",
"water_max": "Maximum watering time/volume",
"water_step": "Time/volume step",
"parallel": "Zone parallel execution"
"parallel": "Zone parallel execution",
"card_yaml": "Enable creation of entities card yaml"
}
},
"update_program": {
Expand Down
6 changes: 4 additions & 2 deletions custom_components/irrigationprogram/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"rain_behaviour": "Rain sensor behaviour",
"water_max": "Maximum watering time/volume",
"water_step": "Time/volume step",
"parallel": "Zone parallel execution"
"parallel": "Zone parallel execution",
"card_yaml": "Enable creation of entities card yaml"
}
}
}
Expand Down Expand Up @@ -228,7 +229,8 @@
"rain_behaviour": "Rain sensor behaviour",
"water_max": "Maximum watering time/volume",
"water_step": "Time/volume step",
"parallel": "Zone parallel execution"
"parallel": "Zone parallel execution",
"card_yaml": "Enable creation of entities card yaml"
}
},
"update_program": {
Expand Down
6 changes: 4 additions & 2 deletions custom_components/irrigationprogram/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"rain_behaviour": "Comportamento del sensore pioggia",
"water_max": "Tempo/volume massimo di irrigazione",
"water_step": "Intervallo di tempo/volume",
"parallel": "Esecuzione parallela a zone"
"parallel": "Esecuzione parallela a zone",
"card_yaml": "Enable creation of entities card yaml"
}
}
}
Expand Down Expand Up @@ -228,7 +229,8 @@
"rain_behaviour": "Comportamento del sensore pioggia",
"water_max": "Tempo/volume massimo di irrigazione",
"water_step": "Intervallo di tempo/volume",
"parallel": "Esecuzione parallela a zone"
"parallel": "Esecuzione parallela a zone",
"card_yaml": "Enable creation of entities card yaml"
}
},
"update_program": {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/irrigationprogram/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ async def should_run(self, scheduled=True):
return False
if not scheduled:
return True
if self.next_run.native_value > dt_util.as_local(dt_util.now()):
if self.next_run.native_value > dt_util.as_local(dt_util.now()):
return False

return True
Expand Down

0 comments on commit 34d5262

Please sign in to comment.