From 1e419b6d8e774b34fec54759f23bbc1cbc15d596 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 2 Mar 2021 14:13:56 +0100 Subject: [PATCH] My plugin updates (#16806) Co-authored-by: Bram Kragten --- .textlintrc.json | 3 +- plugins/my.rb | 46 +++++++++++++++++-- sass/custom/_paulus.scss | 1 - source/_docs/automation/services.markdown | 10 ++-- source/_docs/automation/templating.markdown | 2 +- .../automation/using_blueprints.markdown | 6 +-- .../asides/component_navigation.html | 2 +- source/_includes/common-tasks/snapshots.md | 18 +++----- source/_includes/integrations/config_flow.md | 4 +- 9 files changed, 61 insertions(+), 31 deletions(-) diff --git a/.textlintrc.json b/.textlintrc.json index 67f435bca75..aaf0c0dcc69 100644 --- a/.textlintrc.json +++ b/.textlintrc.json @@ -173,6 +173,7 @@ "MJPEG", "MQTT", "Mullvad", + "My Home Assistant", "MySensors", "NAS", "NETGEAR", @@ -278,7 +279,6 @@ "XML", "Yamaha MusicCast", "Yamaha", - "YAML", "Yandex", "Yeelight", "YouTube", @@ -302,7 +302,6 @@ ["cancelled", "canceled"], ["client ?side", "client-side"], ["colour", "color"], - ["config\\b", "configuration"], ["DarkSky", "Dark Sky"], ["docs\\b", "documentation"], ["e\\.g\\.", "e.g.,"], diff --git a/plugins/my.rb b/plugins/my.rb index 948e7efaf06..b785fb737f1 100644 --- a/plugins/my.rb +++ b/plugins/my.rb @@ -12,11 +12,11 @@ module Jekyll else raise SyntaxError, <<~MSG Syntax error in tag 'my' while parsing the following options: - ` + #{args} Valid syntax: - {% my [title="Link name"] [badge] [icon[="icon-puzzle-piece"]] [addon="core_ssh"] [blueprint_url=""] [domain="hue"] %} + {% my [title="Link name"] [badge] [icon[="icon-puzzle-piece"]] [addon="core_ssh"] [blueprint_url="http://example.com/blueprint.yaml"] [domain="hue"] [service="light.turn_on"] %} MSG end end @@ -33,24 +33,39 @@ module Jekyll query += [["addon", options[:addon]]] if options.include? :addon query += [["blueprint_url", options[:blueprint_url]]] if options.include? :blueprint_url query += [["domain", options[:domain]]] if options.include? :domain + query += [["service", options[:service]]] if options.include? :service unless query.empty? uri.query = URI.encode_www_form(query) end if options[:badge] - title = options[:title] ? options[:title].gsub(/\ /, '_') : @redirect + raise ArgumentError, "Badges cannot have custom titles" if options[:title] ""\ - ""\ + ""\ "" else - title = options[:title] ? options[:title] : @redirect.gsub(/_/, ' ').titlecase + title = @redirect.gsub(/_/, ' ').titlecase icon = "" + + if options[:title] + # Custom title + title = options[:title] + elsif @redirect == "developer_call_service" + # Developer service call + title = "Call Service" + title = "`#{options[:service]}`" if options.include? :service + elsif DEFAULT_TITLES.include?(@redirect) + # Lookup defaults + title = DEFAULT_TITLES[@redirect] + end + if options[:icon] raise ArgumentError, "No default icon for redirect #{@redirect}" \ if !!options[:icon] == options[:icon] and ! DEFAULT_ICONS.include?(@redirect) icon = !!options[:icon] == options[:icon] ? DEFAULT_ICONS[@redirect] : @options[:icon] icon = " " end + "#{icon}#{title}" end end @@ -60,11 +75,32 @@ module Jekyll SYNTAX = %r!^([a-z_]+)((\s+\w+(=([\w\.]+?|".+?"))?)*)$!.freeze OPTIONS_REGEX = %r!(?:\w="[^"]*"|\w=[\w\.]+|\w)+!.freeze + # Default icons when used in in-line text DEFAULT_ICONS = { "config_flow_start" => "icon-plus-sign", + "config" => "icon-cog", "integrations" => "icon-puzzle-piece", } + # Default title used for in-line text + DEFAULT_TITLES = { + "blueprint_import" => "Import Blueprint", + "cloud" => "Home Assistant Cloud", + "config_flow_start" => "Add Integration", + "config_mqtt" => "MQTT Configuration", + "config_zha" => "ZHA Configuration", + "config_zwave_js" => "Z-Wave JS Configuration", + "config" => "Configuration", + "developer_events" => "Events", + "developer_services" => "Services", + "developer_states" => "States", + "developer_template" => "Templates", + "general" => "General Settings", + "info" => "Information", + "supervisor_info" => "Supervisor Information", + "supervisor_snapshots" => "Snapshots", + } + def parse_options(input, context) options = {} return options if input.empty? diff --git a/sass/custom/_paulus.scss b/sass/custom/_paulus.scss index e313c289ff9..2dba14063b2 100644 --- a/sass/custom/_paulus.scss +++ b/sass/custom/_paulus.scss @@ -676,6 +676,5 @@ code { a.my { img { border: 0px; - border-radius: 3px; } } diff --git a/source/_docs/automation/services.markdown b/source/_docs/automation/services.markdown index 57525889bde..40e9ceaf90d 100644 --- a/source/_docs/automation/services.markdown +++ b/source/_docs/automation/services.markdown @@ -5,7 +5,7 @@ description: "How to use the various automation services." The automation integration has services to control automations, like turning automations on and off. This can be useful if you want to disable an automation from another automation. -## Service `automation.turn_on` +## Service {% my developer_call_service service="automation.turn_on" %} This service enables the automation's triggers. @@ -13,7 +13,7 @@ Service data attribute | Optional | Description -|-|- `entity_id` | no | Entity ID of automation to turn on. Can be a list. `none` or `all` are also accepted. -## Service `automation.turn_off` +## Service {% my developer_call_service service="automation.turn_off" %} This service disables the automation's triggers, and optionally stops any currently active actions. @@ -22,7 +22,7 @@ Service data attribute | Optional | Description `entity_id` | no | Entity ID of automation to turn on. Can be a list. `none` or `all` are also accepted. `stop_actions` | yes | Stop any currently active actions (defaults to true). -## Service `automation.toggle` +## Service {% my developer_call_service service="automation.toggle" %} This service enables the automation's triggers if they were disabled, or disables the automation's triggers, and stops any currently active actions, if the triggers were enabled. @@ -30,7 +30,7 @@ Service data attribute | Optional | Description -|-|- `entity_id` | no | Entity ID of automation to turn on. Can be a list. `none` or `all` are also accepted. -## Service `automation.trigger` +## Service {% my developer_call_service service="automation.trigger" %} This service will trigger the action of an automation. By default it bypasses any conditions, though that can be changed via the `skip_condition` attribute. @@ -39,7 +39,7 @@ Service data attribute | Optional | Description `entity_id` | no | Entity ID of automation to trigger. Can be a list. `none` or `all` are also accepted. `skip_condition` | yes | Whether or not the condition will be skipped (defaults to true). -## Service `automation.reload` +## Service {% my developer_call_service service="automation.reload" %} _This service is only required if you create/edit automations in YAML. Automations via the UI do this automatically._ diff --git a/source/_docs/automation/templating.markdown b/source/_docs/automation/templating.markdown index 15baca1e931..0b72cd1e459 100644 --- a/source/_docs/automation/templating.markdown +++ b/source/_docs/automation/templating.markdown @@ -7,7 +7,7 @@ Automations support [templating](/docs/configuration/templating/) in the same wa
- Be aware that if you reference a `trigger` state object in templates of an automation' `action` or `condition` sections, attempting to test that automation by calling the `automation.trigger` service or by clicking EXECUTE in the More Info box for the automation will not work. This is because the trigger state object doesn't exist in those contexts. One way to test automations like these is to manually check that the templates work as expected by pasting them in Developer Tools > Template together with your trigger's definition like: + Be aware that if you reference a `trigger` state object in templates of an automation' `action` or `condition` sections, attempting to test that automation by calling the `automation.trigger` service or by clicking EXECUTE in the More Info box for the automation will not work. This is because the trigger state object doesn't exist in those contexts. One way to test automations like these is to manually check that the templates work as expected by pasting them in {% my developer_template title="Developer Tools > Template" %} together with your trigger's definition like: {%raw%} diff --git a/source/_docs/automation/using_blueprints.markdown b/source/_docs/automation/using_blueprints.markdown index 5f10a2d25a1..a17617bacd1 100644 --- a/source/_docs/automation/using_blueprints.markdown +++ b/source/_docs/automation/using_blueprints.markdown @@ -13,11 +13,11 @@ Quick links: Automations based on a blueprint only need to be configured to be used. What needs to be configured differs on each blueprint. -To create your first automation based on a blueprint, go to **Configuration** and then **Blueprints**. Find the blueprint that you want to use and click on "Create Automation". +To create your first automation based on a blueprint, go to **{% my config %}** and then **{% my blueprints %}**. Find the blueprint that you want to use and click on "Create Automation". This will open the automation editor with the blueprint selected. Give it a name and configure the blueprint and click on the blue button "Save Automation" in the bottom right. -Done! If you want to revisit the configuration values, you can find it by going to **Configuration** and then **Automations**. +Done! If you want to revisit the configuration values, you can find it by going to **{% my config %}** and then **{% my automations %}**. ## Importing blueprints @@ -29,7 +29,7 @@ To do this, first [find a blueprint you want to import][blueprint-forums]. If yo https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml ``` -Go to **Configuration** and then **Blueprints**. Click on the blue "Import Blueprint" button in the bottom right. +Go to **{% my config %}** and then **{% my blueprints %}**. Click on the blue "{% my blueprint_import blueprint="https://github.com/home-assistant/core/blob/master/homeassistant/components/automation/blueprints/motion_light.yaml" %} button in the bottom right. A new dialog will pop-up asking you for the URL. Enter the URL and click on "preview blueprint". diff --git a/source/_includes/asides/component_navigation.html b/source/_includes/asides/component_navigation.html index e93dfc2c5a9..75a809b5399 100644 --- a/source/_includes/asides/component_navigation.html +++ b/source/_includes/asides/component_navigation.html @@ -8,7 +8,7 @@ {%- endif -%} {%- if page.ha_config_flow and page.ha_domain -%} - {% my config_flow_start badge title="Add Integration" domain=page.ha_domain %} + {% my config_flow_start badge domain=page.ha_domain %} {%- endif -%}
diff --git a/source/_includes/common-tasks/snapshots.md b/source/_includes/common-tasks/snapshots.md index b806173f345..49f33abd950 100644 --- a/source/_includes/common-tasks/snapshots.md +++ b/source/_includes/common-tasks/snapshots.md @@ -14,7 +14,7 @@ A partial snapshot consists of any number of the above default directories and i ### Making a Snapshot from the UI -1. Go to Supervisor > Snapshots in the UI +1. Go to {% my supervisor_snapshots title="Supervisor > Snapshots" %} in the UI 2. Provide a name for the snapshot. 3. Choose full or partial. 4. Choose to password protect or not. Password protected snapshots cannot easily be browsed outside of Home Assistant OS @@ -33,7 +33,7 @@ When the upload is completed, you will be presented with the snapshot restore di If the snapshot you are uploading is more than 1GB in size, it can be faster and more efficient to make use of the Samba add-on in order to transfer files to the `/backup` directory. -The length of time it takes to create or restore snapshots will depend on how much you have to compress or decompress. +The length of time it takes to create or restore snapshots will depend on how much you have to compress or decompress. If you're looking to slim down your snapshots, check if your configuration directory contains a large database file (`home-assistant_v2.db`). See the [`recorder`](https://www.home-assistant.io/components/recorder/) integration page for options to keep your database data down to a size that won't cause issues. Note the keep days, purge interval, and include/exclude options. @@ -52,12 +52,8 @@ Use `ha help` to see more info. You often need a snapshot in case your system has crashed. If you only store them on the crashed device, you won't be able to access it easily. We recommend that you manually copy them from `/backup` to another machine on occasion. Or even better, create an automation to handle that, or make use of one of the following add-ons: - - [Google Drive Backup](https://github.com/sabeechen/hassio-google-drive-backup) - - - [Dropbox Sync](https://github.com/danielwelch/hassio-dropbox-sync) - - - [Nextcloud Backup](https://github.com/Sebclem/hassio-nextcloud-backup) - - - [Samba backup](https://github.com/thomasmauerer/hassio-addons/tree/master/samba-backup) - - - [Remote Backup (uses scp)](https://github.com/overkill32/hassio-remote-backup) \ No newline at end of file +- [Google Drive Backup](https://github.com/sabeechen/hassio-google-drive-backup) +- [Dropbox Sync](https://github.com/danielwelch/hassio-dropbox-sync) +- [Nextcloud Backup](https://github.com/Sebclem/hassio-nextcloud-backup) +- [Samba backup](https://github.com/thomasmauerer/hassio-addons/tree/master/samba-backup) +- [Remote Backup (uses scp)](https://github.com/overkill32/hassio-remote-backup) diff --git a/source/_includes/integrations/config_flow.md b/source/_includes/integrations/config_flow.md index ff49aa3acb3..20c04db3e1a 100644 --- a/source/_includes/integrations/config_flow.md +++ b/source/_includes/integrations/config_flow.md @@ -6,7 +6,7 @@ Adding {{ name }} to your Home Assistant instance can be done via the user interface, by taking the following steps: - Browse to your Home Assistant instance. -- In the sidebar click on _**Configuration**_. +- In the sidebar click on _**{% my config icon %}**_. - From the configuration menu select: _**{% my integrations icon %}**_. {% if include.discovery or page.ha_dhcp or page.ha_homekit or page.ha_ssdp or page.ha_zeroconf %} @@ -20,7 +20,7 @@ manual integration entry: {% endif %} - In the bottom right, click on the - _**{% my config_flow_start icon title="Add Integration" domain=page.ha_domain %}**_ button. + _**{% my config_flow_start icon domain=page.ha_domain %}**_ button. - From the list, search and select _**"{{ name }}"**_. - Follow the instruction on screen to complete the set up.