Skip to content

Commit

Permalink
My plugin updates (home-assistant#16806)
Browse files Browse the repository at this point in the history
Co-authored-by: Bram Kragten <[email protected]>
  • Loading branch information
frenck and bramkragten committed Mar 3, 2021
1 parent 2dc57d4 commit 1e419b6
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .textlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
"MJPEG",
"MQTT",
"Mullvad",
"My Home Assistant",
"MySensors",
"NAS",
"NETGEAR",
Expand Down Expand Up @@ -278,7 +279,6 @@
"XML",
"Yamaha MusicCast",
"Yamaha",
"YAML",
"Yandex",
"Yeelight",
"YouTube",
Expand All @@ -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.,"],
Expand Down
46 changes: 41 additions & 5 deletions plugins/my.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def initialize(tag_name, args, tokens)
else
raise SyntaxError, <<~MSG
Syntax error in tag 'my' while parsing the following options:
`
#{args}
Valid syntax:
{% my <redirect> [title="Link name"] [badge] [icon[="icon-puzzle-piece"]] [addon="core_ssh"] [blueprint_url=""] [domain="hue"] %}
{% my <redirect> [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
Expand All @@ -33,24 +33,39 @@ def render(context)
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]
"<a href='#{uri}' class='my badge' target='_blank'>"\
"<img src='https://img.shields.io/badge/#{title}-my?style=for-the-badge&label=MY&logo=home-assistant&color=41BDF5&logoColor=white' />"\
"<img src='https://my.home-assistant.io/badges/#{@redirect}.svg' />"\
"</a>"
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 = "<i class='#{icon}' /> "
end

"#{icon}<a href='#{uri}' class='my' target='_blank'>#{title}</a>"
end
end
Expand All @@ -60,11 +75,32 @@ def render(context)
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?
Expand Down
1 change: 0 additions & 1 deletion sass/custom/_paulus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,5 @@ code {
a.my {
img {
border: 0px;
border-radius: 3px;
}
}
10 changes: 5 additions & 5 deletions source/_docs/automation/services.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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.

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.

Expand All @@ -22,15 +22,15 @@ 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.

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.

Expand All @@ -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._

Expand Down
2 changes: 1 addition & 1 deletion source/_docs/automation/templating.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Automations support [templating](/docs/configuration/templating/) in the same wa

<div class='note'>

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%}

Expand Down
6 changes: 3 additions & 3 deletions source/_docs/automation/using_blueprints.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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".

Expand Down
2 changes: 1 addition & 1 deletion source/_includes/asides/component_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
</div>

Expand Down
18 changes: 7 additions & 11 deletions source/_includes/common-tasks/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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)
- [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)
4 changes: 2 additions & 2 deletions source/_includes/integrations/config_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i class="icon-cog"/> _**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 %}
Expand All @@ -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.

Expand Down

0 comments on commit 1e419b6

Please sign in to comment.