Merge branch 'current' into next

This commit is contained in:
Franck Nijhof 2019-07-18 23:57:08 +02:00
commit bd2e4898d7
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
3 changed files with 60 additions and 10 deletions

View File

@ -7,6 +7,11 @@ module Jekyll
'icon' => '/docs/configuration/customizing-devices/#icon', 'icon' => '/docs/configuration/customizing-devices/#icon',
} }
TYPES = [
'action', 'boolean', 'string', 'integer', 'float', 'time', 'template',
'device_class', 'icon', 'map', 'list', 'date', 'datetime'
]
def initialize(tag_name, text, tokens) def initialize(tag_name, text, tokens)
super super
@component, @platform = text.strip.split('.', 2) @component, @platform = text.strip.split('.', 2)
@ -48,7 +53,7 @@ module Jekyll
end end
end end
def render_config_vars(vars:, component:, platform:, classes: nil) def render_config_vars(vars:, component:, platform:, converter:, classes: nil, parent_type: nil)
result = Array.new result = Array.new
result << "<dl class='#{classes}'>" result << "<dl class='#{classes}'>"
@ -57,20 +62,56 @@ module Jekyll
markup << "<dt><a class='title-link' name='#{slug(key)}' href='\##{slug(key)}'></a> #{key}</dt>" markup << "<dt><a class='title-link' name='#{slug(key)}' href='\##{slug(key)}'></a> #{key}</dt>"
markup << "<dd>" markup << "<dd>"
markup << "<p class='desc'>" markup << "<p class='desc'>"
if attr.key? 'type' if attr.key? 'type'
# Check if the type (or list of types) are valid
if attr['type'].kind_of? Array
attr['type'].each do |type|
raise ArgumentError, "Configuration type '#{type}' for key '#{key}' is not a valid type in the documentation."\
" See: https://developers.home-assistant.io/docs/en/documentation_create_page.html#configuration" unless \
TYPES.include? type
end
else
raise ArgumentError, "Configuration type '#{attr['type']}' for key '#{key}' is not a valid type in the documentation."\
" See: https://developers.home-assistant.io/docs/en/documentation_create_page.html#configuration" unless \
TYPES.include? attr['type']
end
markup << "<span class='type'>(<span class='#{type_class(attr['type'])}'>" markup << "<span class='type'>(<span class='#{type_class(attr['type'])}'>"
markup << "#{type_link(attr['type'], component: component)}</span>)</span>" markup << "#{type_link(attr['type'], component: component)}</span>)</span>"
else
# Type is missing, which is required (unless we are in a list or template)
raise ArgumentError, "Configuration key '#{key}' is missing a type definition" \
unless ['list', 'template'].include? parent_type
end end
if attr.key? 'required' if attr.key? 'required'
# Check if required is a valid value
raise ArgumentError, "Configuration key '#{key}' required field must be specified as: "\
"true, false, inclusive or exclusive."\
unless [true, false, 'inclusive', 'exclusive'].include? attr['required']
markup << "<span class='required'>(#{required_value(attr['required'])})</span>" markup << "<span class='required'>(#{required_value(attr['required'])})</span>"
end end
if attr.key? 'description' if attr.key? 'description'
markup << "<span class='description'>#{attr['description']}</span>" markup << "<span class='description'>#{converter.convert(attr['description'].to_s)}</span>"
else
# Description is missing
raise ArgumentError, "Configuration key '#{key}' is missing a description."
end end
markup << "</p>" markup << "</p>"
if attr.key? 'default'
markup << "<p class='default'>Default value: #{attr['default']}</p>" if attr.key? 'default' and not attr['default'].to_s.empty?
markup << "<p class='default'>\nDefault value: #{converter.convert(attr['default'].to_s)}</p>"
elsif attr['type'].to_s.include? 'boolean'
# Is the type is a boolean, a default key is required
raise ArgumentError, "Configuration key '#{key}' is a boolean type and"\
" therefore, requires a default."
end end
markup << "</dd>" markup << "</dd>"
# Check for nested configuration variables # Check for nested configuration variables
@ -78,7 +119,8 @@ module Jekyll
markup << "<dd>" markup << "<dd>"
markup << render_config_vars( markup << render_config_vars(
vars: attr['keys'], component: component, vars: attr['keys'], component: component,
platform: platform, classes: 'nested') platform: platform, converter: converter,
classes: 'nested', parent_type: attr['type'])
markup << "</dd>" markup << "</dd>"
end end
@ -100,12 +142,20 @@ module Jekyll
component = Liquid::Template.parse(@component).render context component = Liquid::Template.parse(@component).render context
platform = Liquid::Template.parse(@platform).render context platform = Liquid::Template.parse(@platform).render context
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
vars = SafeYAML.load(contents) vars = SafeYAML.load(contents)
<<~MARKUP <<~MARKUP
<div class="config-vars"> <div class="config-vars">
<h3><a class="title-link" name="configuration-variables" href="#configuration-variables"></a> Configuration Variables</h3> <h3><a class="title-link" name="configuration-variables" href="#configuration-variables"></a> Configuration Variables</h3>
#{render_config_vars(vars: vars, component: component, platform: platform)} #{render_config_vars(
vars: vars,
component: component,
platform: platform,
converter: converter
)}
</div> </div>
MARKUP MARKUP
end end

View File

@ -107,7 +107,7 @@ mode_state_template:
required: false required: false
type: template type: template
modes: modes:
description: A list of supported modes. description: A list of supported modes. Needs to be a subset of the default values.
required: false required: false
default: ['auto', 'off', 'cool', 'heat', 'dry', 'fan_only'] default: ['auto', 'off', 'cool', 'heat', 'dry', 'fan_only']
type: list type: list

View File

@ -59,16 +59,16 @@ switch:
switches: switches:
ac: ac:
friendly_name: "AC" friendly_name: "AC"
value_template: "{{ is_state('climate.ac', 'cool') or is_state('climate.ac', 'heat') or is_state('climate.ac', 'dry') or is_state('climate.ac', 'heat')}}" value_template: "{{ is_state('climate.ac', 'cool') or is_state('climate.ac', 'heat') or is_state('climate.ac', 'dry') or is_state('climate.ac', 'fan_only') }}"
turn_on: turn_on:
service: climate.set_havc_mode service: climate.set_havc_mode
data: data:
entity_id: climate.ac entity_id: climate.ac
hvac_mode: off hvac_mode: cool
turn_off: turn_off:
service: climate.set_havc_mode service: climate.set_havc_mode
data: data:
entity_id: climate.ac entity_id: climate.ac
hvac_mode: hvac_mode: off
``` ```
{% endraw %} {% endraw %}