home-assistant-ecosystem / home-assistant-cli

:computer: Command-line tool for Home Assistant
Other
446 stars 69 forks source link

Feature request: run external script on 'hass-cli entity rename' with from and to parameters #318

Closed haakonstorm closed 4 years ago

haakonstorm commented 4 years ago

Feature request: run external script on 'hass-cli entity rename' with from and to parameters

I'm thinking of a solution where hass-cli aids in this.

The Awesomest Way

hass-cli --refactor zwave.8f1f9f9b-switch-power-relay-nerdfont-compatible-device zwave.maindoor "Main Door Sensor"

My reasoning: because usually both entity_id and friendly name is changed at the same time, but not always (sometimes keep nil, set to nil, or do not change) and due to zsh/bash + complexities of escaping meta characters: Having end users enter friendly names directly as a parameter to hass-cli, when additional parameters might be passed, is a recipe for unwanted snafu, I think. I don't know a good way to solve this, perhaps apart from hass-cli either implenting some sort of readline to grab and sanity check the user input .. or implementing a "yes/no" prompt after displaying what hass-cli interpreted as the input for from_id and to_id / to_friendlyname.

Also awesome

`hass-cli entity rename zwave.8f1f9f9b-nerdfont-compatible zwave.maindoor "Door Sensor" --exec_on_success /path/to/hass-cli-refactor.sh'

If that rename succeeds:

I don't know if hass-cli already supports exit codes somehow, but with so many different outcomes to a rename, I thought it might be best for the logic and/or string sanitizing be done within a 'proper programming language' and for the results of that sanitizing to be passed to an external tool. Or, hass-cli does the blanket find and replace of all matches in /config itself. Are there any other places than the .yaml files have references that would need updating?

What do you guys think?

On a side note: I've daemonized hass-cli event watch state_changed via launchctl and also a helper tool parsing that output. Now I'm notified via bitbar on the macOS menu bar of changes on entity attributes registered in the simple tool. A native --daemonize would be awesome!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.