summaryrefslogtreecommitdiff
path: root/src/home
diff options
context:
space:
mode:
Diffstat (limited to 'src/home')
-rw-r--r--src/home/inverter/monitor.py4
-rw-r--r--src/home/inverter/types.py11
2 files changed, 11 insertions, 4 deletions
diff --git a/src/home/inverter/monitor.py b/src/home/inverter/monitor.py
index f661d73..86f75ac 100644
--- a/src/home/inverter/monitor.py
+++ b/src/home/inverter/monitor.py
@@ -113,9 +113,7 @@ class InverterMonitor(Thread):
# Reading rated configuration
rated = inverter.exec('get-rated')['data']
- self.osp = OutputSourcePriority.SolarBatteryUtility \
- if rated['output_source_priority'] == 'Solar-Battery-Utility' \
- else OutputSourcePriority.SolarUtilityBattery
+ self.osp = OutputSourcePriority.from_text(rated['output_source_priority'])
# Read data and run implemented programs every 2 seconds.
while not self.interrupted:
diff --git a/src/home/inverter/types.py b/src/home/inverter/types.py
index 0292c15..57021f1 100644
--- a/src/home/inverter/types.py
+++ b/src/home/inverter/types.py
@@ -52,4 +52,13 @@ class ACMode(Enum):
class OutputSourcePriority(Enum):
SolarUtilityBattery = 'SUB'
- SolarBatteryUtility = 'SBU' \ No newline at end of file
+ SolarBatteryUtility = 'SBU'
+
+ @classmethod
+ def from_text(cls, s: str):
+ if s == 'Solar-Battery-Utility':
+ return cls.SolarBatteryUtility
+ elif s == 'Solar-Utility-Battery':
+ return cls.SolarUtilityBattery
+ else:
+ raise ValueError(f'unknown value: {s}') \ No newline at end of file