haydnw / AirPi

A Raspberry Pi air quality station
27 stars 15 forks source link

GPS print.py output exception #38

Open hostaboat opened 8 years ago

hostaboat commented 8 years ago

When trying to print to console via print.py with GPS enabled, there is no GPS output, no '=' delimiter line between readings, and in the airpi.log file I see the following:

2016-09-25 17:01:05,689 - __main__ - DEBUG -  ERROR:   Exception during output: Unknown format code 'f' for object of type 'str'

The breakage seems to have happened In the commit by Haydn Williams on Oct 15, 2014 - Lots of pylint improvements.

This part of the commit in format_output_gps() broke GPS output:

 100       -        return str(prop.ljust(17) + ": " + str("{0:.2f}".format(value)).rjust(10) + " " + unit) 
      147  +        value = str(prop.ljust(17)) + ": "
      148  +        value += str("{0:.2f}".format(value).rjust(10) + " " + unit) 

Note that value is passed in as an argument then immediately overwritten and assigned a value that is a string. When it is then appended to, the attempt to format what is now a string as a float causes the exception.

GPS output works by just changing back with an ljust(18) to match the other outputs:

return str(prop.ljust(18)) + ": " + str("{0:.2f}".format(value).rjust(10) + " " + unit)