mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-06 12:41:37 +02:00
Merge branch 'nrf_container' of https://github.com/vendetta1987/ahoy into vendetta1987-nrf_container
This commit is contained in:
commit
24b9be867c
4 changed files with 59 additions and 38 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -13,3 +13,5 @@ src/web/html/tmp/*
|
||||||
*.suo
|
*.suo
|
||||||
*.ipch
|
*.ipch
|
||||||
src/output.map
|
src/output.map
|
||||||
|
|
||||||
|
/.venv
|
||||||
|
|
|
@ -345,6 +345,9 @@ class HoymilesNRF:
|
||||||
if not radio.begin():
|
if not radio.begin():
|
||||||
raise RuntimeError('Can\'t open radio')
|
raise RuntimeError('Can\'t open radio')
|
||||||
|
|
||||||
|
if not radio.isChipConnected():
|
||||||
|
logging.warning("could not connect to NRF24 radio")
|
||||||
|
|
||||||
self.txpower = radio_config.get('txpower', 'max')
|
self.txpower = radio_config.get('txpower', 'max')
|
||||||
|
|
||||||
self.radio = radio
|
self.radio = radio
|
||||||
|
@ -411,7 +414,7 @@ class HoymilesNRF:
|
||||||
self.radio.startListening()
|
self.radio.startListening()
|
||||||
|
|
||||||
fragments = []
|
fragments = []
|
||||||
|
received_sth=False
|
||||||
# Receive: Loop
|
# Receive: Loop
|
||||||
t_end = time.monotonic_ns()+timeout
|
t_end = time.monotonic_ns()+timeout
|
||||||
while time.monotonic_ns() < t_end:
|
while time.monotonic_ns() < t_end:
|
||||||
|
@ -431,7 +434,7 @@ class HoymilesNRF:
|
||||||
ch_rx=self.rx_channel, ch_tx=self.tx_channel,
|
ch_rx=self.rx_channel, ch_tx=self.tx_channel,
|
||||||
time_rx=datetime.now()
|
time_rx=datetime.now()
|
||||||
)
|
)
|
||||||
|
received_sth=True
|
||||||
yield fragment
|
yield fragment
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -447,7 +450,11 @@ class HoymilesNRF:
|
||||||
self.radio.setChannel(self.rx_channel)
|
self.radio.setChannel(self.rx_channel)
|
||||||
self.radio.startListening()
|
self.radio.startListening()
|
||||||
|
|
||||||
time.sleep(0.004)
|
time.sleep(0.005)
|
||||||
|
|
||||||
|
if not received_sth:
|
||||||
|
raise TimeoutError
|
||||||
|
|
||||||
|
|
||||||
def next_rx_channel(self):
|
def next_rx_channel(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -103,10 +103,11 @@ class SunsetHandler:
|
||||||
def sun_status2mqtt(self, dtu_ser, dtu_name):
|
def sun_status2mqtt(self, dtu_ser, dtu_name):
|
||||||
if not mqtt_client or not self.suntimes:
|
if not mqtt_client or not self.suntimes:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.suntimes:
|
||||||
local_sunrise = self.suntimes.riselocal(datetime.now()).strftime("%d.%m.%YT%H:%M")
|
local_sunrise = self.suntimes.riselocal(datetime.now()).strftime("%d.%m.%YT%H:%M")
|
||||||
local_sunset = self.suntimes.setlocal(datetime.now()).strftime("%d.%m.%YT%H:%M")
|
local_sunset = self.suntimes.setlocal(datetime.now()).strftime("%d.%m.%YT%H:%M")
|
||||||
local_zone = self.suntimes.setlocal(datetime.now()).tzinfo._key
|
local_zone = self.suntimes.setlocal(datetime.now()).tzinfo.key
|
||||||
if self.suntimes:
|
|
||||||
mqtt_client.info2mqtt({'topic' : f'{dtu_name}/{dtu_ser}'}, \
|
mqtt_client.info2mqtt({'topic' : f'{dtu_name}/{dtu_ser}'}, \
|
||||||
{'dis_night_comm' : 'True', \
|
{'dis_night_comm' : 'True', \
|
||||||
'local_sunrise' : local_sunrise, \
|
'local_sunrise' : local_sunrise, \
|
||||||
|
@ -235,7 +236,7 @@ def poll_inverter(inverter, dtu_ser, do_init, retries):
|
||||||
if isinstance(result, hoymiles.decoders.StatusResponse):
|
if isinstance(result, hoymiles.decoders.StatusResponse):
|
||||||
|
|
||||||
data = result.__dict__()
|
data = result.__dict__()
|
||||||
if 'event_count' in data:
|
if data is not None and 'event_count' in data:
|
||||||
if event_message_index[inv_str] < data['event_count']:
|
if event_message_index[inv_str] < data['event_count']:
|
||||||
event_message_index[inv_str] = data['event_count']
|
event_message_index[inv_str] = data['event_count']
|
||||||
command_queue[inv_str].append(hoymiles.compose_send_time_payload(InfoCommands.AlarmData, alarm_id=event_message_index[inv_str]))
|
command_queue[inv_str].append(hoymiles.compose_send_time_payload(InfoCommands.AlarmData, alarm_id=event_message_index[inv_str]))
|
||||||
|
@ -409,7 +410,7 @@ if __name__ == '__main__':
|
||||||
str(g_inverter_ser),
|
str(g_inverter_ser),
|
||||||
g_inverter.get('mqtt', {}).get('topic', f'hoymiles/{g_inverter_ser}') + '/command'
|
g_inverter.get('mqtt', {}).get('topic', f'hoymiles/{g_inverter_ser}') + '/command'
|
||||||
)
|
)
|
||||||
mqtt_client.subscribe(topic_item[1])
|
mqtt_client.client.subscribe(topic_item[1])
|
||||||
mqtt_command_topic_subs.append(topic_item)
|
mqtt_command_topic_subs.append(topic_item)
|
||||||
|
|
||||||
# start main-loop
|
# start main-loop
|
||||||
|
|
|
@ -227,6 +227,11 @@ class MqttOutputPlugin(OutputPluginFactory):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = response.__dict__()
|
data = response.__dict__()
|
||||||
|
|
||||||
|
if data is None:
|
||||||
|
logging.warn("received data object is empty")
|
||||||
|
return
|
||||||
|
|
||||||
topic = params.get('topic', None)
|
topic = params.get('topic', None)
|
||||||
if not topic:
|
if not topic:
|
||||||
topic = f'{data.get("inverter_name", "hoymiles")}/{data.get("inverter_ser", None)}'
|
topic = f'{data.get("inverter_name", "hoymiles")}/{data.get("inverter_ser", None)}'
|
||||||
|
@ -243,6 +248,7 @@ class MqttOutputPlugin(OutputPluginFactory):
|
||||||
# AC Data
|
# AC Data
|
||||||
phase_id = 0
|
phase_id = 0
|
||||||
phase_sum_power = 0
|
phase_sum_power = 0
|
||||||
|
if data['phases'] is not None:
|
||||||
for phase in data['phases']:
|
for phase in data['phases']:
|
||||||
self.client.publish(f'{topic}/emeter/{phase_id}/voltage', phase['voltage'], self.qos, self.ret)
|
self.client.publish(f'{topic}/emeter/{phase_id}/voltage', phase['voltage'], self.qos, self.ret)
|
||||||
self.client.publish(f'{topic}/emeter/{phase_id}/current', phase['current'], self.qos, self.ret)
|
self.client.publish(f'{topic}/emeter/{phase_id}/current', phase['current'], self.qos, self.ret)
|
||||||
|
@ -255,6 +261,7 @@ class MqttOutputPlugin(OutputPluginFactory):
|
||||||
# DC Data
|
# DC Data
|
||||||
string_id = 0
|
string_id = 0
|
||||||
string_sum_power = 0
|
string_sum_power = 0
|
||||||
|
if data['strings'] is not None:
|
||||||
for string in data['strings']:
|
for string in data['strings']:
|
||||||
if 'name' in string:
|
if 'name' in string:
|
||||||
string_name = string['name'].replace(" ","_")
|
string_name = string['name'].replace(" ","_")
|
||||||
|
@ -279,17 +286,21 @@ class MqttOutputPlugin(OutputPluginFactory):
|
||||||
self.client.publish(f'{topic}/YieldTotal', data['yield_total']/1000, self.qos, self.ret)
|
self.client.publish(f'{topic}/YieldTotal', data['yield_total']/1000, self.qos, self.ret)
|
||||||
if data['yield_today'] is not None:
|
if data['yield_today'] is not None:
|
||||||
self.client.publish(f'{topic}/YieldToday', data['yield_today']/1000, self.qos, self.ret)
|
self.client.publish(f'{topic}/YieldToday', data['yield_today']/1000, self.qos, self.ret)
|
||||||
|
if data['efficiency'] is not None:
|
||||||
self.client.publish(f'{topic}/Efficiency', data['efficiency'], self.qos, self.ret)
|
self.client.publish(f'{topic}/Efficiency', data['efficiency'], self.qos, self.ret)
|
||||||
|
|
||||||
|
|
||||||
elif isinstance(response, HardwareInfoResponse):
|
elif isinstance(response, HardwareInfoResponse):
|
||||||
|
if data["FW_ver_maj"] is not None and data["FW_ver_min"] is not None and data["FW_ver_pat"] is not None:
|
||||||
self.client.publish(f'{topic}/Firmware/Version',\
|
self.client.publish(f'{topic}/Firmware/Version',\
|
||||||
f'{data["FW_ver_maj"]}.{data["FW_ver_min"]}.{data["FW_ver_pat"]}', self.qos, self.ret)
|
f'{data["FW_ver_maj"]}.{data["FW_ver_min"]}.{data["FW_ver_pat"]}', self.qos, self.ret)
|
||||||
|
|
||||||
|
if data["FW_build_dd"] is not None and data["FW_build_mm"] is not None and data["FW_build_yy"] is not None and data["FW_build_HH"] is not None and data["FW_build_MM"] is not None:
|
||||||
self.client.publish(f'{topic}/Firmware/Build_at',\
|
self.client.publish(f'{topic}/Firmware/Build_at',\
|
||||||
f'{data["FW_build_dd"]}/{data["FW_build_mm"]}/{data["FW_build_yy"]}T{data["FW_build_HH"]}:{data["FW_build_MM"]}',\
|
f'{data["FW_build_dd"]}/{data["FW_build_mm"]}/{data["FW_build_yy"]}T{data["FW_build_HH"]}:{data["FW_build_MM"]}',\
|
||||||
self.qos, self.ret)
|
self.qos, self.ret)
|
||||||
|
|
||||||
|
if data["FW_HW_ID"] is not None:
|
||||||
self.client.publish(f'{topic}/Firmware/HWPartId',\
|
self.client.publish(f'{topic}/Firmware/HWPartId',\
|
||||||
f'{data["FW_HW_ID"]}', self.qos, self.ret)
|
f'{data["FW_HW_ID"]}', self.qos, self.ret)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue