From 7bfe66eb56558602fc42744ab9e9437cb63ffed6 Mon Sep 17 00:00:00 2001
From: Paul Chote
Date: Fri, 12 Jul 2024 00:33:53 +0100
Subject: [PATCH] Replace TFmt with Rich.
---
chiller | 10 +++++-----
rockit/chiller/constants.py | 32 +++++++++++++++-----------------
2 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/chiller b/chiller
index a6b7bfa..2cea2b5 100755
--- a/chiller
+++ b/chiller
@@ -23,7 +23,7 @@ import json
import os
import sys
import Pyro4
-from rockit.common import TFmt
+from rockit.common import print
from rockit.chiller import Config, ChillerMode, ChillerStatus, CommandStatus
SCRIPT_NAME = os.path.basename(sys.argv[0])
@@ -63,13 +63,13 @@ def print_status(config, _):
data = chiller.report_status()
date = datetime.datetime.strptime(data['date'], '%Y-%m-%dT%H:%M:%SZ')
- print(f'Data received {TFmt.Bold}{date}{TFmt.Clear}:')
+ print(f'Data received [b]{date}[/b]:')
print(' Chiller is ' + ChillerStatus.label(data['status'], True))
print(f' Mode is ' + ChillerMode.label(data['mode'], True))
if 'water_temp' in data:
- print(f' Temperature is {TFmt.Bold}{data["water_temp"]}\u00B0C{TFmt.Clear}')
- print(f' Set point is {TFmt.Bold}{data["setpoint_temp"]}\u00B0C{TFmt.Clear}')
- print(f' TEC power is {TFmt.Bold}{data["tec_power"]}%{TFmt.Clear}')
+ print(f' Temperature is [b]{data["water_temp"]}\u00B0C[/b]')
+ print(f' Set point is [b]{data["setpoint_temp"]}\u00B0C[/b]')
+ print(f' TEC power is [b]{data["tec_power"]}%[/b]')
return 0
diff --git a/rockit/chiller/constants.py b/rockit/chiller/constants.py
index bd39194..59f0621 100644
--- a/rockit/chiller/constants.py
+++ b/rockit/chiller/constants.py
@@ -16,8 +16,6 @@
"""Constants and status codes used by chillerd"""
-from rockit.common import TFmt
-
class CommandStatus:
"""Numeric return codes"""
@@ -57,9 +55,9 @@ class ChillerMode:
1: 'AUTOMATIC'
}
- _formats = {
- 0: TFmt.Yellow + TFmt.Bold,
- 1: TFmt.Green + TFmt.Bold
+ _colors = {
+ 0: 'yellow',
+ 1: 'green'
}
@classmethod
@@ -69,9 +67,9 @@ def label(cls, status, formatting=False):
Set formatting=true to enable terminal formatting characters
"""
if formatting:
- if status in cls._formats and status in cls._formats:
- return cls._formats[status] + cls._labels[status] + TFmt.Clear
- return TFmt.Red + TFmt.Bold + 'UNKNOWN' + TFmt.Clear
+ if status in cls._labels and status in cls._colors:
+ return f'[b][{cls._colors[status]}]{cls._labels[status]}[/{cls._colors[status]}][/b]'
+ return '[b][red]UNKNOWN[/red][/b]'
if status in cls._labels:
return cls._labels[status]
@@ -89,11 +87,11 @@ class ChillerStatus:
3: 'HEATING'
}
- _formats = {
- 0: TFmt.Bold + TFmt.Red,
- 1: TFmt.Bold,
- 2: TFmt.Bold + TFmt.Cyan,
- 3: TFmt.Bold + TFmt.Yellow,
+ _colors = {
+ 0: 'red',
+ 1: 'default',
+ 2: 'cyan',
+ 3: 'yellow'
}
@classmethod
@@ -103,10 +101,10 @@ def label(cls, status, formatting=False):
Set formatting=true to enable terminal formatting characters
"""
if formatting:
- if status in cls._formats and status in cls._formats:
- return cls._formats[status] + cls._labels[status] + TFmt.Clear
- return TFmt.Red + TFmt.Bold + 'UNKNOWN STATUS' + TFmt.Clear
+ if status in cls._labels and status in cls._colors:
+ return f'[b][{cls._colors[status]}]{cls._labels[status]}[/{cls._colors[status]}][/b]'
+ return '[b][red]UNKNOWN[/red][/b]'
if status in cls._labels:
return cls._labels[status]
- return 'UNKNOWN STATUS'
+ return 'UNKNOWN'
\ No newline at end of file