找到问题了,大佬的这段代码没有添加认证,所以discovery的消息根本没有发送成功。。。我Python也渣渣,等大佬修复吧。。。
class RinnaiHomeAssistantDiscovery(MQTTClientBase):
def __init__(self,config):
super().__init__("rinnai_ha_discovery")
self.config = config
self.mqtt_host = self.config.LOCAL_MQTT_HOST
self.mqtt_port = self.config.LOCAL_MQTT_PORT
self.unique_id = "rinnai_heater"
self.discovery_prefix = "homeassistant"
if self.config.LOCAL_MQTT_TLS :
self.client.tls_set(
cert_reqs=ssl.CERT_NONE,
tls_version=ssl.PROTOCOL_TLSv1_2
)
self.client.tls_insecure_set(True)
logging.info("Local MQTT TLS enabled")
if self.config.LOCAL_MQTT_USERNAME and self.config.LOCAL_MQTT_PASSWORD:
self.client.username_pw_set(
self.config.LOCAL_MQTT_USERNAME, self.config.LOCAL_MQTT_PASSWORD)
logging.info("Local MQTT authentication enabled")
|