Send proxy values when the inverter disconnets
This commit is contained in:
@@ -35,7 +35,7 @@ class Inverter(AsyncStream):
|
|||||||
logging.debug ("disconnect client connection")
|
logging.debug ("disconnect client connection")
|
||||||
self.remoteStream.disc()
|
self.remoteStream.disc()
|
||||||
|
|
||||||
# await self.async_publ_mqtt()
|
await self.__async_publ_mqtt_packet('proxy')
|
||||||
|
|
||||||
async def client_loop(self, addr):
|
async def client_loop(self, addr):
|
||||||
'''Loop for receiving messages from the TSUN cloud (client-side)'''
|
'''Loop for receiving messages from the TSUN cloud (client-side)'''
|
||||||
@@ -73,8 +73,6 @@ class Inverter(AsyncStream):
|
|||||||
|
|
||||||
async def async_publ_mqtt(self) -> None:
|
async def async_publ_mqtt(self) -> None:
|
||||||
'''puplish data to MQTT broker'''
|
'''puplish data to MQTT broker'''
|
||||||
db = self.db.db
|
|
||||||
stat = self.db.stat
|
|
||||||
# check if new inverter or collector infos are available or when the home assistant has changed the status back to online
|
# check if new inverter or collector infos are available or when the home assistant has changed the status back to online
|
||||||
if (('inverter' in self.new_data and self.new_data['inverter']) or
|
if (('inverter' in self.new_data and self.new_data['inverter']) or
|
||||||
('collector' in self.new_data and self.new_data['collector']) or
|
('collector' in self.new_data and self.new_data['collector']) or
|
||||||
@@ -83,18 +81,23 @@ class Inverter(AsyncStream):
|
|||||||
self.ha_restarts = self.mqtt.ha_restarts
|
self.ha_restarts = self.mqtt.ha_restarts
|
||||||
|
|
||||||
for key in self.new_data:
|
for key in self.new_data:
|
||||||
if self.new_data[key]:
|
await self.__async_publ_mqtt_packet(key)
|
||||||
if key in db:
|
|
||||||
data_json = json.dumps(db[key])
|
async def __async_publ_mqtt_packet(self, key):
|
||||||
node_id = self.node_id
|
db = self.db.db
|
||||||
elif key in stat:
|
stat = self.db.stat
|
||||||
data_json = json.dumps(stat[key])
|
if self.new_data[key]:
|
||||||
node_id = self.proxy_node_id
|
if key in db:
|
||||||
else:
|
data_json = json.dumps(db[key])
|
||||||
continue
|
node_id = self.node_id
|
||||||
logger_mqtt.debug(f'{key}: {data_json}')
|
elif key in stat:
|
||||||
await self.mqtt.publish(f"{self.entity_prfx}{node_id}{key}", data_json)
|
data_json = json.dumps(stat[key])
|
||||||
self.new_data[key] = False
|
node_id = self.proxy_node_id
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
logger_mqtt.debug(f'{key}: {data_json}')
|
||||||
|
await self.mqtt.publish(f"{self.entity_prfx}{node_id}{key}", data_json)
|
||||||
|
self.new_data[key] = False
|
||||||
|
|
||||||
async def __register_home_assistant(self) -> None:
|
async def __register_home_assistant(self) -> None:
|
||||||
'''register all our topics at home assistant'''
|
'''register all our topics at home assistant'''
|
||||||
|
|||||||
Reference in New Issue
Block a user