Skip to content

Instantly share code, notes, and snippets.

@koter84
Last active January 27, 2023 14:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koter84/86790850aa63354bda56d041de31dc70 to your computer and use it in GitHub Desktop.
Save koter84/86790850aa63354bda56d041de31dc70 to your computer and use it in GitHub Desktop.
#!/bin/bash
self_file="$0"
self_source_url="https://raw.githubusercontent.com/koter84/HomeAssistant_Blueprints_Update/main/blueprints_update.sh"
# print info function
function _blueprint_update_info
{
echo "$@"
}
# create a temp file for downloading
_tempfile=$(mktemp -t blueprints_update.XXXXXX)
# start message
_blueprint_update_info "> ${self_file}"
# update
wget -q -O "${_tempfile}" "${self_source_url}"
wget_result=$?
if [ "${wget_result}" != "0" ]
then
_blueprint_update_info "! something went wrong while downloading, exiting..."
_blueprint_update_info
exit
fi
self_diff=$(diff "${self_file}" "${_tempfile}")
if [ "${self_diff}" == "" ]
then
_blueprint_update_info "-> self up-2-date"
else
cp "${_tempfile}" "${self_file}"
chmod +x "${self_file}"
_blueprint_update_info "-! self updated!"
exit
fi
_blueprint_update_info
@3v1n0
Copy link

3v1n0 commented Nov 23, 2022

I'd like to be able to update also from shell, so could you please change the cd line in something like:

cd /config/blueprints || cd $(dirname "$0")/../config/blueprints || exit 1

@3v1n0
Copy link

3v1n0 commented Nov 23, 2022

There are various bugs in the handling of blueprints with no source_url set:

  • custom- uri's are not preserved:
    • ideally if the updated script has no source_url set it should be re-added (without custom- prefix, that breaks HA).
  • The value is added to the file using a wrong syntax (leading to HA not to load it, breaking automations)
    • It should not use source_url:, but source_url: ''.

This is the error when the invalid source_url value is found:

2022-11-23 02:40:10.661 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Invalid blueprint: invalid url for dictionary value @ data['blueprint']['source_url']. Got None (See ?, line ?). 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 61, in __init__
    data = self.data = BLUEPRINT_SCHEMA(data)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 433, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: invalid url for dictionary value @ data['blueprint']['source_url']
The above exception was the direct cause of the following exception:
```

So the value should be set to the files which have no 

@SirGoodenough
Copy link

SirGoodenough commented Dec 16, 2022

Thanks for this @koter84 .I did some initial troubleshooting with you on this and it looks great here.

I've noticed that blueprint filenames that have spaces or non alpha characters get confused and comes back with non-matching filename. I think this worked at one time, it is not now from this gist version anyway.

Another thing that seemed confused was if I add custom- to a source url, it finds it, updates it, but the url is not in the file when it comes back. Instead we get - source_url: and a blank which fails syntax in HA. I'm pretty sure that was fine early on as well.

I'm thinking perhaps an in-between version is posted here.

Also if there is a way the shell can return a flag if there are updates needed or not would be great. I'm not really wanting to have it just update when I'm not there when it tuns in a timer. I would prefer it runs on the timer, returns some data that we can grab in HA to do a persistent_notification that updates need to be checked. (Webhook with some json message(s), perhaps?)

An enhancement request would be another switch that takes a filename so a single file could be checked or updated as opposed to all.

@koter84
Copy link
Author

koter84 commented Jan 25, 2023

i have made a full github repository for this script, which you can find on https://github.com/koter84/HomeAssistant_Blueprints_Update/

i'm currently fixing some errors and adding a couple of features, once i commit that to the new repository i'll update this script to auto-update to that repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment