1414_logger = logging .getLogger (__name__ )
1515
1616
17+ def _format_number (value : Any ) -> str :
18+ """Format number to one decimal place if float, otherwise return as-is."""
19+ if isinstance (value , float ):
20+ return f"{ value :.1f} "
21+ return str (value )
22+
23+
1724def _json_default_serializer (obj : Any ) -> Any :
1825 """Serialize objects not serializable by default json code.
1926
@@ -213,7 +220,7 @@ def print_device_status(device_status: Any) -> None:
213220 (
214221 "OPERATION STATUS" ,
215222 "Current Power" ,
216- f"{ device_status .current_inst_power } W" ,
223+ f"{ _format_number ( device_status .current_inst_power ) } W" ,
217224 )
218225 )
219226
@@ -223,47 +230,47 @@ def print_device_status(device_status: Any) -> None:
223230 (
224231 "WATER TEMPERATURES" ,
225232 "DHW Current" ,
226- f"{ device_status .dhw_temperature } °F" ,
233+ f"{ _format_number ( device_status .dhw_temperature ) } °F" ,
227234 )
228235 )
229236 if hasattr (device_status , "dhw_target_temperature_setting" ):
230237 all_items .append (
231238 (
232239 "WATER TEMPERATURES" ,
233240 "DHW Target" ,
234- f"{ device_status .dhw_target_temperature_setting } °F" ,
241+ f"{ _format_number ( device_status .dhw_target_temperature_setting ) } °F" ,
235242 )
236243 )
237244 if hasattr (device_status , "tank_upper_temperature" ):
238245 all_items .append (
239246 (
240247 "WATER TEMPERATURES" ,
241248 "Tank Upper" ,
242- f"{ device_status .tank_upper_temperature } °F" ,
249+ f"{ _format_number ( device_status .tank_upper_temperature ) } °F" ,
243250 )
244251 )
245252 if hasattr (device_status , "tank_lower_temperature" ):
246253 all_items .append (
247254 (
248255 "WATER TEMPERATURES" ,
249256 "Tank Lower" ,
250- f"{ device_status .tank_lower_temperature } °F" ,
257+ f"{ _format_number ( device_status .tank_lower_temperature ) } °F" ,
251258 )
252259 )
253260 if hasattr (device_status , "current_inlet_temperature" ):
254261 all_items .append (
255262 (
256263 "WATER TEMPERATURES" ,
257264 "Inlet Temp" ,
258- f"{ device_status .current_inlet_temperature } °F" ,
265+ f"{ _format_number ( device_status .current_inlet_temperature ) } °F" ,
259266 )
260267 )
261268 if hasattr (device_status , "current_dhw_flow_rate" ):
262269 all_items .append (
263270 (
264271 "WATER TEMPERATURES" ,
265272 "DHW Flow Rate" ,
266- device_status .current_dhw_flow_rate ,
273+ _format_number ( device_status .current_dhw_flow_rate ) ,
267274 )
268275 )
269276
@@ -273,15 +280,15 @@ def print_device_status(device_status: Any) -> None:
273280 (
274281 "AMBIENT TEMPERATURES" ,
275282 "Outside" ,
276- f"{ device_status .outside_temperature } °F" ,
283+ f"{ _format_number ( device_status .outside_temperature ) } °F" ,
277284 )
278285 )
279286 if hasattr (device_status , "ambient_temperature" ):
280287 all_items .append (
281288 (
282289 "AMBIENT TEMPERATURES" ,
283290 "Ambient" ,
284- f"{ device_status .ambient_temperature } °F" ,
291+ f"{ _format_number ( device_status .ambient_temperature ) } °F" ,
285292 )
286293 )
287294
@@ -291,39 +298,39 @@ def print_device_status(device_status: Any) -> None:
291298 (
292299 "SYSTEM TEMPERATURES" ,
293300 "Discharge" ,
294- f"{ device_status .discharge_temperature } °F" ,
301+ f"{ _format_number ( device_status .discharge_temperature ) } °F" ,
295302 )
296303 )
297304 if hasattr (device_status , "suction_temperature" ):
298305 all_items .append (
299306 (
300307 "SYSTEM TEMPERATURES" ,
301308 "Suction" ,
302- f"{ device_status .suction_temperature } °F" ,
309+ f"{ _format_number ( device_status .suction_temperature ) } °F" ,
303310 )
304311 )
305312 if hasattr (device_status , "evaporator_temperature" ):
306313 all_items .append (
307314 (
308315 "SYSTEM TEMPERATURES" ,
309316 "Evaporator" ,
310- f"{ device_status .evaporator_temperature } °F" ,
317+ f"{ _format_number ( device_status .evaporator_temperature ) } °F" ,
311318 )
312319 )
313320 if hasattr (device_status , "target_super_heat" ):
314321 all_items .append (
315322 (
316323 "SYSTEM TEMPERATURES" ,
317324 "Target SuperHeat" ,
318- device_status .target_super_heat ,
325+ _format_number ( device_status .target_super_heat ) ,
319326 )
320327 )
321328 if hasattr (device_status , "current_super_heat" ):
322329 all_items .append (
323330 (
324331 "SYSTEM TEMPERATURES" ,
325332 "Current SuperHeat" ,
326- device_status .current_super_heat ,
333+ _format_number ( device_status .current_super_heat ) ,
327334 )
328335 )
329336
@@ -333,31 +340,31 @@ def print_device_status(device_status: Any) -> None:
333340 (
334341 "HEAT PUMP SETTINGS" ,
335342 "Upper On" ,
336- f"{ device_status .hp_upper_on_temp_setting } °F" ,
343+ f"{ _format_number ( device_status .hp_upper_on_temp_setting ) } °F" ,
337344 )
338345 )
339346 if hasattr (device_status , "hp_upper_off_temp_setting" ):
340347 all_items .append (
341348 (
342349 "HEAT PUMP SETTINGS" ,
343350 "Upper Off" ,
344- f"{ device_status .hp_upper_off_temp_setting } °F" ,
351+ f"{ _format_number ( device_status .hp_upper_off_temp_setting ) } °F" ,
345352 )
346353 )
347354 if hasattr (device_status , "hp_lower_on_temp_setting" ):
348355 all_items .append (
349356 (
350357 "HEAT PUMP SETTINGS" ,
351358 "Lower On" ,
352- f"{ device_status .hp_lower_on_temp_setting } °F" ,
359+ f"{ _format_number ( device_status .hp_lower_on_temp_setting ) } °F" ,
353360 )
354361 )
355362 if hasattr (device_status , "hp_lower_off_temp_setting" ):
356363 all_items .append (
357364 (
358365 "HEAT PUMP SETTINGS" ,
359366 "Lower Off" ,
360- f"{ device_status .hp_lower_off_temp_setting } °F" ,
367+ f"{ _format_number ( device_status .hp_lower_off_temp_setting ) } °F" ,
361368 )
362369 )
363370
@@ -367,31 +374,31 @@ def print_device_status(device_status: Any) -> None:
367374 (
368375 "HEAT ELEMENT SETTINGS" ,
369376 "Upper On" ,
370- f"{ device_status .he_upper_on_temp_setting } °F" ,
377+ f"{ _format_number ( device_status .he_upper_on_temp_setting ) } °F" ,
371378 )
372379 )
373380 if hasattr (device_status , "he_upper_off_temp_setting" ):
374381 all_items .append (
375382 (
376383 "HEAT ELEMENT SETTINGS" ,
377384 "Upper Off" ,
378- f"{ device_status .he_upper_off_temp_setting } °F" ,
385+ f"{ _format_number ( device_status .he_upper_off_temp_setting ) } °F" ,
379386 )
380387 )
381388 if hasattr (device_status , "he_lower_on_temp_setting" ):
382389 all_items .append (
383390 (
384391 "HEAT ELEMENT SETTINGS" ,
385392 "Lower On" ,
386- f"{ device_status .he_lower_on_temp_setting } °F" ,
393+ f"{ _format_number ( device_status .he_lower_on_temp_setting ) } °F" ,
387394 )
388395 )
389396 if hasattr (device_status , "he_lower_off_temp_setting" ):
390397 all_items .append (
391398 (
392399 "HEAT ELEMENT SETTINGS" ,
393400 "Lower Off" ,
394- f"{ device_status .he_lower_off_temp_setting } °F" ,
401+ f"{ _format_number ( device_status .he_lower_off_temp_setting ) } °F" ,
395402 )
396403 )
397404
@@ -401,85 +408,91 @@ def print_device_status(device_status: Any) -> None:
401408 (
402409 "POWER & ENERGY" ,
403410 "Total Consumption" ,
404- f"{ device_status .wh_total_power_consumption } Wh" ,
411+ f"{ _format_number ( device_status .wh_total_power_consumption ) } Wh" ,
405412 )
406413 )
407414 if hasattr (device_status , "wh_heat_pump_power" ):
408415 all_items .append (
409416 (
410417 "POWER & ENERGY" ,
411418 "Heat Pump Power" ,
412- f"{ device_status .wh_heat_pump_power } Wh" ,
419+ f"{ _format_number ( device_status .wh_heat_pump_power ) } Wh" ,
413420 )
414421 )
415422 if hasattr (device_status , "wh_electric_heater_power" ):
416423 all_items .append (
417424 (
418425 "POWER & ENERGY" ,
419426 "Electric Heater Power" ,
420- f"{ device_status .wh_electric_heater_power } Wh" ,
427+ f"{ _format_number ( device_status .wh_electric_heater_power ) } Wh" ,
421428 )
422429 )
423430 if hasattr (device_status , "total_energy_capacity" ):
424431 all_items .append (
425432 (
426433 "POWER & ENERGY" ,
427434 "Total Capacity" ,
428- device_status .total_energy_capacity ,
435+ _format_number ( device_status .total_energy_capacity ) ,
429436 )
430437 )
431438 if hasattr (device_status , "available_energy_capacity" ):
432439 all_items .append (
433440 (
434441 "POWER & ENERGY" ,
435442 "Available Capacity" ,
436- device_status .available_energy_capacity ,
443+ _format_number ( device_status .available_energy_capacity ) ,
437444 )
438445 )
439446
440447 # Fan Control
441448 if hasattr (device_status , "target_fan_rpm" ):
449+ target_rpm = _format_number (device_status .target_fan_rpm )
442450 all_items .append (
443- ("FAN CONTROL" , "Target RPM" , device_status . target_fan_rpm )
451+ ("FAN CONTROL" , "Target RPM" , target_rpm )
444452 )
445453 if hasattr (device_status , "current_fan_rpm" ):
454+ current_rpm = _format_number (device_status .current_fan_rpm )
446455 all_items .append (
447- ("FAN CONTROL" , "Current RPM" , device_status . current_fan_rpm )
456+ ("FAN CONTROL" , "Current RPM" , current_rpm )
448457 )
449458 if hasattr (device_status , "fan_pwm" ):
450- all_items .append (("FAN CONTROL" , "PWM" , f"{ device_status .fan_pwm } %" ))
459+ pwm_pct = f"{ _format_number (device_status .fan_pwm )} %"
460+ all_items .append (("FAN CONTROL" , "PWM" , pwm_pct ))
451461 if hasattr (device_status , "cumulated_op_time_eva_fan" ):
462+ eva_fan_time = _format_number (device_status .cumulated_op_time_eva_fan )
452463 all_items .append (
453464 (
454465 "FAN CONTROL" ,
455466 "Eva Fan Time" ,
456- device_status . cumulated_op_time_eva_fan ,
467+ eva_fan_time ,
457468 )
458469 )
459470
460471 # Compressor & Valve
461472 if hasattr (device_status , "mixing_rate" ):
473+ mixing = _format_number (device_status .mixing_rate )
462474 all_items .append (
463- ("COMPRESSOR & VALVE" , "Mixing Rate" , device_status . mixing_rate )
475+ ("COMPRESSOR & VALVE" , "Mixing Rate" , mixing )
464476 )
465477 if hasattr (device_status , "eev_step" ):
478+ eev = _format_number (device_status .eev_step )
466479 all_items .append (
467- ("COMPRESSOR & VALVE" , "EEV Step" , device_status . eev_step )
480+ ("COMPRESSOR & VALVE" , "EEV Step" , eev )
468481 )
469482 if hasattr (device_status , "target_super_heat" ):
470483 all_items .append (
471484 (
472485 "COMPRESSOR & VALVE" ,
473486 "Target SuperHeat" ,
474- device_status .target_super_heat ,
487+ _format_number ( device_status .target_super_heat ) ,
475488 )
476489 )
477490 if hasattr (device_status , "current_super_heat" ):
478491 all_items .append (
479492 (
480493 "COMPRESSOR & VALVE" ,
481494 "Current SuperHeat" ,
482- device_status .current_super_heat ,
495+ _format_number ( device_status .current_super_heat ) ,
483496 )
484497 )
485498
@@ -505,15 +518,15 @@ def print_device_status(device_status: Any) -> None:
505518 (
506519 "RECIRCULATION" ,
507520 "Temperature" ,
508- f"{ device_status .recirc_temperature } °F" ,
521+ f"{ _format_number ( device_status .recirc_temperature ) } °F" ,
509522 )
510523 )
511524 if hasattr (device_status , "recirc_faucet_temperature" ):
512525 all_items .append (
513526 (
514527 "RECIRCULATION" ,
515528 "Faucet Temp" ,
516- f"{ device_status .recirc_faucet_temperature } °F" ,
529+ f"{ _format_number ( device_status .recirc_faucet_temperature ) } °F" ,
517530 )
518531 )
519532
@@ -577,8 +590,9 @@ def print_device_status(device_status: Any) -> None:
577590
578591 # WiFi & Network
579592 if hasattr (device_status , "wifi_rssi" ):
593+ rssi_dbm = f"{ _format_number (device_status .wifi_rssi )} dBm"
580594 all_items .append (
581- ("WiFi & NETWORK" , "RSSI" , f" { device_status . wifi_rssi } dBm" )
595+ ("WiFi & NETWORK" , "RSSI" , rssi_dbm )
582596 )
583597
584598 # Demand Response & TOU
0 commit comments