From c4fe5cffe68805caca4d8b4c9f42fe16f700cd57 Mon Sep 17 00:00:00 2001 From: Laurent Martin Date: Sun, 5 May 2024 10:49:42 +0200 Subject: [PATCH] #24 add comment method --- bin/ets_to_hass | 2 +- lib/ets_to_hass/generator.rb | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bin/ets_to_hass b/bin/ets_to_hass index 3c11f26..63a1039 100755 --- a/bin/ets_to_hass +++ b/bin/ets_to_hass @@ -33,7 +33,7 @@ opts = GetoptLong.new( ['--trace', '-t', GetoptLong::REQUIRED_ARGUMENT], ['--output', '-o', GetoptLong::REQUIRED_ARGUMENT], ['--password', '-p', GetoptLong::REQUIRED_ARGUMENT], - ['--comment-skipped', '-c', GetoptLong::REQUIRED_ARGUMENT] + ['--comment-skipped', '-c', GetoptLong::NO_ARGUMENT] ) options = {} diff --git a/lib/ets_to_hass/generator.rb b/lib/ets_to_hass/generator.rb index 64bb4c5..6385c46 100755 --- a/lib/ets_to_hass/generator.rb +++ b/lib/ets_to_hass/generator.rb @@ -27,7 +27,8 @@ class Generator ETS_FUNCTIONS_INDEX_TO_NAME = %i[custom switchable_light dimmable_light sun_protection heating_radiator heating_floor dimmable_light sun_protection heating_switching_variable heating_continuous_variable].freeze - private_constant :ETS_EXT, :ETS_FUNCTIONS_INDEX_TO_NAME + NOT_IMPLEMENTED = 'not_implemented' + private_constant :ETS_EXT, :ETS_FUNCTIONS_INDEX_TO_NAME, :NOT_IMPLEMENTED # class methods class << self @@ -247,9 +248,9 @@ def map_ets_function_to_ha_object_category(ets_func) when :sun_protection then 'cover' when :custom, :heating_continuous_variable, :heating_floor, :heating_radiator, :heating_switching_variable @logger.warn("#{ets_func[:room].red} #{ets_func[:name].green} function type #{ets_func[:type].to_s.blue} not implemented") - nil + NOT_IMPLEMENTED else @logger.error("#{ets_func[:room].red} #{ets_func[:name].green} function type #{ets_func[:type].to_s.blue} not supported, please report") - nil + NOT_IMPLEMENTED end end @@ -341,16 +342,14 @@ def generate_homeass next unless ga_object_ids(ga_id).empty? ga_data = group_address_data(ga_id) warning(ga_data[:address], ga_data[:name], 'Group not in object: use ETS to create functions or use specific code') + add_comment("#{ga_data[:address]}: #{ga_data[:name]}") if @opts[:comment_skipped] end # Generate devices from either functions in ETS, or from specific code all_object_ids.each do |object_id| ets_object = object(object_id) # compute object domain, this is the section in HA configuration (switch, light, etc...) ha_object_domain = ets_object[:ha].delete(:domain) || map_ets_function_to_ha_object_category(ets_object) - if ha_object_domain.nil? - warning(ets_object[:name], ets_object[:room], "#{ets_object[:type].to_s.blue}: function type not detected, skipping") - next - end + warning(ets_object[:name], ets_object[:room], "#{ets_object[:type].to_s.blue}: function type not mapped, skipping") if ha_object_domain.eql?(NOT_IMPLEMENTED) # add domain to config, if necessary ha_config[ha_object_domain] ||= [] # HA configuration object, either empty or initialized in specific code @@ -392,6 +391,10 @@ def generate_homeass @logger.info('Sorting by name') ha_config.each_value { |v| v.sort_by! { |o| o['name'] } } end + # remove not implemented objects + ha_config.delete(NOT_IMPLEMENTED)&.each do |o| + add_comment("#{o}") if @opts[:comment_skipped] + end # add knx level, if user asks for it ha_config = { 'knx' => ha_config } if @opts[:ha_knx] [