Skip to content

Commit

Permalink
#24 add comment method
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-martin committed May 5, 2024
1 parent 274059a commit c4fe5cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bin/ets_to_hass
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
17 changes: 10 additions & 7 deletions lib/ets_to_hass/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
[
Expand Down

0 comments on commit c4fe5cf

Please sign in to comment.