sander1988 / Indego

Home Assistant Custom Component for Bosch Indego Lawn Mower
Apache License 2.0
92 stars 29 forks source link

Deleting alerts on multiple mowers #211

Closed RolandE1204 closed 3 months ago

RolandE1204 commented 4 months ago

I do have multiple mowers and want to delete all alerts from one of the mowers. indego.delete_alert_all is not working. How can I do this?

kimzeuner commented 4 months ago

I think i found a solution by adding the mower serial to the alert services. I will give you an explanation for the changes that need to be done tomorrow. I can not test it 100% as i only have one mower but i think it should work. When you have tested it and confirmed that it works i will write a pull request for including it in the official version.

kimzeuner commented 4 months ago

Here are the changes that you can test.

  1. in custom_components/indego/services.yaml add the folowing code to all 4 alert features

    mower_serial:
      description: The serial of the mower for this action. Only required when you have multiple mowers configured.
      example: '"0123456789"'
      required: false

    it should look like this (here as an example for the service "delete alert", as i said you have to repeat this for the other 3 alert features)

    delete_alert:
    description: Delete the selected Alert
    fields:
    mower_serial:
      description: The serial of the mower for this action. Only required when you have multiple mowers configured.
      example: '"0123456789"'
      required: false
    alert_index: 
      description: Delete the selected Alert in this case the latest
      example: "0"
  2. in custom_components/indego/init.py search for "SERVICE_SCHEMA_DELETE_ALERT = vol.Schema({" and add the line

    vol.Optional(CONF_MOWER_SERIAL): cv.string,

    so it should look like this

    SERVICE_SCHEMA_DELETE_ALERT = vol.Schema({
    vol.Optional(CONF_MOWER_SERIAL): cv.string,
    vol.Required(CONF_DELETE_ALERT): cv.positive_int
    })

    again repeat that for the other 3 alert features.

  3. in custom_components/indego/init.py search for "async def async_delete_alert(call):" and change the code from

    async def async_delete_alert(call):
        """Handle the service call."""
        enable = call.data.get(CONF_DELETE_ALERT, DEFAULT_NAME_COMMANDS)
        _LOGGER.debug("Indego.delete_alert service called, with command: %s", enable)
        await hass.data[DOMAIN][entry.entry_id]._update_alerts()
        await hass.data[DOMAIN][entry.entry_id]._indego_client.delete_alert(enable)
        await hass.data[DOMAIN][entry.entry_id]._update_alerts()     

to

    async def async_delete_alert(call):
        """Handle the service call."""
        instance = find_instance_for_mower_service_call(call)
        enable = call.data.get(CONF_DELETE_ALERT, DEFAULT_NAME_COMMANDS)
        _LOGGER.debug("Indego.delete_alert service called, with command: %s", enable)
        await instance._update_alerts()
        await instance._indego_client.delete_alert(enable)
        await instance._update_alerts()    

also here you have to repeat this for the other 3 alert features. important is to add the line

instance = find_instance_for_mower_service_call(call)

and change

hass.data[DOMAIN][entry.entry_id].

to

 instance.

As an alternative you can download the files init.py and services.yaml copy them to your custom_components/indego folder and replace the old ones.

After you made the changes restart Home Assistant.

Please let me know if it works.

sander1988 commented 3 months ago

@kimzeuner - I just did a quick test on my environment. Clearing the alerts works fine here! :-)

One thing... I think we should keep the message in English. I'm referring to "Kein Problem", maybe change this to "No Problem"?

kimzeuner commented 3 months ago

Sure, i will correct that. I have also created a file for german translations so i will upload them with the next pull request 😉

sander1988 commented 3 months ago

I have merged this and optimized the code. It's now available on the develop branch for testing.