44
55from modules .devices .tasmota .tasmota .config import TasmotaCounterSetup
66from modules .common .abstract_device import AbstractCounter
7- from modules .common .tasmota import Tasmota
87from modules .common .component_type import ComponentDescriptor
98from modules .common .fault_state import ComponentInfo , FaultState
109from modules .common .store import get_counter_value_store
10+ from modules .common .simcount import SimCounter
11+ from modules .common import req
12+ from modules .common .component_state import CounterState
1113
1214log = logging .getLogger (__name__ )
1315
@@ -26,14 +28,49 @@ def __init__(self, component_config: TasmotaCounterSetup, **kwargs: Any) -> None
2628 def initialize (self ) -> None :
2729 self .__device_id : int = self .kwargs ['device_id' ]
2830 self .__ip_address : str = self .kwargs ['ip_address' ]
31+ self .sim_counter = SimCounter (self .__device_id , self .component_config .id , prefix = "bezug" )
2932 self .__phase : int = self .kwargs ['phase' ]
3033 self .store = get_counter_value_store (self .component_config .id )
3134 self .fault_state = FaultState (ComponentInfo .from_component_config (self .component_config ))
32- self .__tasmota = Tasmota (self .__device_id , self .__ip_address , self .__phase )
3335
3436 def update (self ):
35- log .debug ("tasmota.counter.update: " + self .__ip_address )
36- counter_state = self .__tasmota .get_CounterState ()
37+ url = "http://" + self .__ip_address + "/cm?cmnd=Status%208"
38+ response = req .get_http_session ().get (url , timeout = 5 ).json ()
39+
40+ if 'ENERGY' in response ['StatusSNS' ]:
41+ voltages = [0.0 , 0.0 , 0.0 ]
42+ powers = [0.0 , 0.0 , 0.0 ]
43+ currents = [0.0 , 0.0 , 0.0 ]
44+ power_factors = [0.0 , 0.0 , 0.0 ]
45+
46+ power = float (response ['StatusSNS' ]['ENERGY' ]['Power' ])
47+ voltages [self .__phase - 1 ] = float (response ['StatusSNS' ]['ENERGY' ]['Voltage' ])
48+ powers [self .__phase - 1 ] = float (response ['StatusSNS' ]['ENERGY' ]['Power' ])
49+ currents [self .__phase - 1 ] = float (response ['StatusSNS' ]['ENERGY' ]['Current' ])
50+ power_factors [self .__phase - 1 ] = float (response ['StatusSNS' ]['ENERGY' ]['Factor' ])
51+ imported = float (response ['StatusSNS' ]['ENERGY' ]['Total' ]* 1000 )
52+ _ , exported = self .sim_counter .sim_count (power )
53+
54+ counter_state = CounterState (
55+ power = power ,
56+ voltages = voltages ,
57+ currents = currents ,
58+ powers = powers ,
59+ power_factors = power_factors ,
60+ imported = imported ,
61+ exported = exported
62+ )
63+ else :
64+ power = float (response ['StatusSNS' ]['Itron' ]['Power' ])
65+ imported = float (response ['StatusSNS' ]['Itron' ]['E_in' ]* 1000 )
66+ exported = float (response ['StatusSNS' ]['Itron' ]['E_out' ]* 1000 )
67+
68+ counter_state = CounterState (
69+ power = power ,
70+ imported = imported ,
71+ exported = exported
72+ )
73+
3774 self .store .set (counter_state )
3875
3976
0 commit comments