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 << "
" + 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 << "