-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.py
70 lines (64 loc) · 3.17 KB
/
objects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import json
import logging
import sys
def first_value(tag):
def fn(results):
if tag in results:
return results[tag]['1'][0]['val']
raise KeyError(f'Tag {tag} not present')
return fn
def second_value(tag):
def fn(results):
if tag in results:
return results[tag]['1'][1]['val']
raise KeyError(f'Tag {tag} not present')
return fn
def scale(factor):
return lambda x: x * factor
sensors = [
('ac_power', first_value('6100_40263F00'), scale(1.0), 'W'),
('ac_active_power_l1', first_value('6100_40464000'), scale(1.0), 'W'),
('ac_active_power_l2', first_value('6100_40464100'), scale(1.0), 'W'),
('ac_active_power_l3', first_value('6100_40464200'), scale(1.0), 'W'),
('ac_phase_voltage_l1', first_value('6100_00464800'), scale(0.01), 'V'),
('ac_phase_voltage_l2', first_value('6100_00464900'), scale(0.01), 'V'),
('ac_phase_voltage_l3', first_value('6100_00464A00'), scale(0.01), 'V'),
('ac_phase_voltage_l1_l2', first_value('6100_00464B00'), scale(0.01), 'V'),
('ac_phase_voltage_l2_l3', first_value('6100_00464C00'), scale(0.01), 'V'),
('ac_phase_voltage_l3_l1', first_value('6100_00464D00'), scale(0.01), 'V'),
('ac_phase_current_l1', first_value('6100_40465300'), scale(0.001), 'A'),
('ac_phase_current_l2', first_value('6100_40465400'), scale(0.001), 'A'),
('ac_phase_current_l3', first_value('6100_40465500'), scale(0.001), 'A'),
('ac_grid_frequency', first_value('6100_00465700'), scale(0.01), 'Hz'),
('ac_pv_generated_power', first_value('6100_0046C200'), scale(1.0), 'W'),
('ac_phase_total_current', first_value('6100_00664F00'), scale(0.001), 'A'),
('ac_displacement_power_factor', first_value('6100_00665900'), scale(0.001), ''),
('ac_eei_displacement_power_factor', first_value('6100_40665B00'), scale(0.001), ''),
('ac_reactive_power', first_value('6100_40665F00'), scale(1.0), 'VAR'),
('ac_reactive_power_l1', first_value('6100_40666000'), scale(1.0), 'VAR'),
('ac_reactive_power_l2', first_value('6100_40666100'), scale(1.0), 'VAR'),
('ac_reactive_power_l3', first_value('6100_40666200'), scale(1.0), 'VAR'),
('ac_apparent_power', first_value('6100_40666700'), scale(1.0), 'VA'),
('ac_apparent_power_l1', first_value('6100_40666800'), scale(1.0), 'VA'),
('ac_apparent_power_l2', first_value('6100_40666900'), scale(1.0), 'VA'),
('ac_apparent_power_l3', first_value('6100_40666A00'), scale(1.0), 'VA'),
('dc_power_a', first_value('6380_40251E00'), scale(1.0), 'W'),
('dc_power_b', second_value('6380_40251E00'), scale(1.0), 'W'),
('dc_voltage_a', first_value('6380_40451F00'), scale(0.01), 'V'),
('dc_voltage_b', second_value('6380_40451F00'), scale(0.01), 'V'),
('dc_current_a', first_value('6380_40452100'), scale(0.001), 'A'),
('dc_current_b', second_value('6380_40452100'), scale(0.001), 'A'),
('ac_total_yield', first_value('6400_00260100'), scale(3600.0), 'J'),
('ac_daily_yield', first_value('6400_00262200'), scale(3600.0), 'J'),
]
def fields(data):
serial, results = next(iter(data['result'].items()), ('', {}))
for field, extract, transform, unit in sensors:
try:
r = extract(results)
except KeyError:
continue
if r is not None:
v = transform(r)
yield (field, v, unit)