some further colorization implemented:
colorCode = '%' if power < 20 else \
'&' if power < 100 else \
'+' if power < 300 else \
'#' if power < 500 else \
'=' if power < 1500 else \
'!' if power < 2000 else \
''
colorCodeTotal = '%' if total_power < 200 else \
'&' if total_power < 500 else \
'+' if total_power < 1000 else \
'#' if total_power < 1500 else \
'=' if total_power < 2000 else \
'!' if total_power < 3000 else \
'*'
and
sensor = colorCode +'{:22}:'.format(state.name[:-8]) + '{:>7}\n'.format(state.state)
sensor_list.append(sensor)
had a little go understanding your new summary style, so forgive me for changing. This is still very much so a learning process…
I kind of like the formatting placeholders in the summary, and the content or variable in the .format()
.
summary = '\n'.join([
'*{:=^20} : {:=^7}', # = 30
*sorted(sensor_list),
'*{:=^30}', # = 30
'/ {:^21}: {:^7}', # = 30
colorCodeTotal +'{:^21}: {:>7.2f}', # = 30
'*' + '='*30 # = 30
]).format(' Sensor ','Power ',
' Summary ',
'Total Sensors consuming power',count,
'Total consumed Power',total_power,
total_power)
Colors are working fine now, so cool. Only thing is, the sorted(sensor_list) now sorts per color unexpected (for me) and have to see if that can be changed to sort alphabetically.
optimally I would like to create the list colorCode =['*','!','+','=','%','$','#']
and have the comparison check for values power <50, 100, 300, 500, 1500, 2000, or else (when >2000) turn ‘*’.
Could(Should) I do that in another way than fully written out like now?
btw, what does the *
do in front of the *sorted(sensor_list)
?
thought it to be a remnant of my colorizations, so took it out, but then the script stops and errors with: TypeError: sequence item 1: expected str instance, list found
.
Could there be a mixup in the code with the * being used for several things?