From 24b09336a3010c8237228c630ea84e4cf50e0474 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 18 Jul 2019 12:07:05 -0700 Subject: [PATCH 1/3] Clarify modes is limited to a specific set. (#9897) --- source/_components/climate.mqtt.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/_components/climate.mqtt.markdown b/source/_components/climate.mqtt.markdown index 575d753fb42..a5f38468a43 100644 --- a/source/_components/climate.mqtt.markdown +++ b/source/_components/climate.mqtt.markdown @@ -107,7 +107,7 @@ mode_state_template: required: false type: template modes: - description: A list of supported modes. + description: A list of supported modes. Needs to be a subset of the default values. required: false default: ['auto', 'off', 'cool', 'heat', 'dry', 'fan_only'] type: list From 4b6997d269309cd294ae82b185a9aba9511eebbb Mon Sep 17 00:00:00 2001 From: Bogdan Alexe Date: Thu, 18 Jul 2019 22:58:04 +0300 Subject: [PATCH 2/3] Fix example (#9899) --- source/_components/sensibo.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/_components/sensibo.markdown b/source/_components/sensibo.markdown index e03717d8a78..1ebefcad72c 100644 --- a/source/_components/sensibo.markdown +++ b/source/_components/sensibo.markdown @@ -59,16 +59,16 @@ switch: switches: 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: service: climate.set_havc_mode data: entity_id: climate.ac - hvac_mode: off + hvac_mode: cool turn_off: service: climate.set_havc_mode data: entity_id: climate.ac - hvac_mode: + hvac_mode: off ``` {% endraw %} From b1e7286c497df1586bddb5746d08e69dbfb61949 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 18 Jul 2019 23:55:13 +0200 Subject: [PATCH 3/3] Adds config validation to configuration plugin (#9886) --- plugins/configuration.rb | 62 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/plugins/configuration.rb b/plugins/configuration.rb index 993e4ba4e6d..dd497576922 100644 --- a/plugins/configuration.rb +++ b/plugins/configuration.rb @@ -7,6 +7,11 @@ module Jekyll '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) super @component, @platform = text.strip.split('.', 2) @@ -48,7 +53,7 @@ module Jekyll 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 << "
" @@ -57,20 +62,56 @@ module Jekyll markup << "
#{key}
" markup << "
" markup << "

" + 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 << "(" markup << "#{type_link(attr['type'], component: component)})" + 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 + + 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 << "(#{required_value(attr['required'])})" end + if attr.key? 'description' - markup << "#{attr['description']}" + markup << "#{converter.convert(attr['description'].to_s)}" + else + # Description is missing + raise ArgumentError, "Configuration key '#{key}' is missing a description." end markup << "

" - if attr.key? 'default' - markup << "

Default value: #{attr['default']}

" + + if attr.key? 'default' and not attr['default'].to_s.empty? + markup << "

\nDefault value: #{converter.convert(attr['default'].to_s)}

" + 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 + markup << "
" # Check for nested configuration variables @@ -78,7 +119,8 @@ module Jekyll markup << "
" markup << render_config_vars( vars: attr['keys'], component: component, - platform: platform, classes: 'nested') + platform: platform, converter: converter, + classes: 'nested', parent_type: attr['type']) markup << "
" end @@ -100,12 +142,20 @@ module Jekyll component = Liquid::Template.parse(@component).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) <<~MARKUP

Configuration Variables

- #{render_config_vars(vars: vars, component: component, platform: platform)} + #{render_config_vars( + vars: vars, + component: component, + platform: platform, + converter: converter + )}
MARKUP end