Skip to content

Commit

Permalink
Replace TFmt with Rich.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Jul 11, 2024
1 parent cd1333c commit 7bfe66e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
10 changes: 5 additions & 5 deletions chiller
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand Down
32 changes: 15 additions & 17 deletions rockit/chiller/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

"""Constants and status codes used by chillerd"""

from rockit.common import TFmt


class CommandStatus:
"""Numeric return codes"""
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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'

0 comments on commit 7bfe66e

Please sign in to comment.