Add DSMR MQTT subscribe error handling (#118316)

Add eror handling
This commit is contained in:
Erwin Douna 2024-06-21 18:52:39 +02:00 committed by GitHub
parent a1884ed821
commit cb563f25fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View File

@ -6,9 +6,12 @@ from homeassistant.components import mqtt
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.util import slugify
from .const import DOMAIN
from .definitions import SENSORS, DSMRReaderSensorEntityDescription
@ -53,6 +56,20 @@ class DSMRSensor(SensorEntity):
self.async_write_ha_state()
await mqtt.async_subscribe(
self.hass, self.entity_description.key, message_received, 1
)
try:
await mqtt.async_subscribe(
self.hass, self.entity_description.key, message_received, 1
)
except HomeAssistantError:
async_create_issue(
self.hass,
DOMAIN,
f"cannot_subscribe_mqtt_topic_{self.entity_description.key}",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="cannot_subscribe_mqtt_topic",
translation_placeholders={
"topic": self.entity_description.key,
"topic_title": self.entity_description.key.split("/")[-1],
},
)

View File

@ -259,5 +259,11 @@
"name": "Quarter-hour peak end time"
}
}
},
"issues": {
"cannot_subscribe_mqtt_topic": {
"title": "Cannot subscribe to MQTT topic {topic_title}",
"description": "The DSMR Reader integration cannot subscribe to the MQTT topic: `{topic}`. Please check the configuration of the MQTT broker and the topic.\nDSMR Reader needs to be running, before starting this integration."
}
}
}