cmroche / OctoPrint-HomeAssistant

Home Assistant plugin for OctoPrint, enabling MQTT discovery of you device and sensors
111 stars 18 forks source link

Fix entity names to avoid breaking change introduced in Home Assistant 2023.8 #113

Closed RobertD502 closed 1 year ago

RobertD502 commented 1 year ago

A change was implemented in Home Assistant 2023.8 that doesn't allow for entity names to be prefixed by a string that is equivalent to the device name. The device name is OctoPrint. All entity names are currently prefixed with this device name (e.g., OctoPrint Emergency stop). Starting in Home Assistant 2023.8, a warning is logged + repair issue raised for each MQTT entity that is using this naming convention:

Logger: homeassistant.components.mqtt.mixins
Source: components/mqtt/mixins.py:294
Integration: MQTT (documentation, issues)
First occurred: 3:16:54 PM (30 occurrences)
Last logged: 3:16:54 PM

MQTT entity name starts with the device name in your config {'availability_topic': 'octoprint/mqtt', 'payload_available': 'connected', 'payload_not_available': 'disconnected', 'name': 'OctoPrint Emergency Stop', 'unique_id': 'CA6944_STOP', 'command_topic': 'octoprint/hassControl/stop', 'device': {'identifiers': ['CA6944'], 'name': 'OctoPrint', 'manufacturer': 'Clifford Roche', 'model': 'HomeAssistant Discovery for OctoPrint', 'sw_version': 'HomeAssistant Discovery for OctoPrint 3.6.5', 'connections': []}, 'icon': 'mdi:alert-octagon', 'qos': 0, 'retain': False, 'encoding': 'utf-8', 'enabled_by_default': True, 'payload_press': 'PRESS', 'availability_mode': 'latest'}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Emergency Stop'
MQTT entity name starts with the device name in your config {'availability_topic': 'octoprint/hass/is_printing', 'payload_available': 'True', 'payload_not_available': 'False', 'name': 'OctoPrint Cancel Print', 'unique_id': 'CA6944_CANCEL', 'command_topic': 'octoprint/hassControl/cancel', 'device': {'identifiers': ['CA6944'], 'name': 'OctoPrint', 'manufacturer': 'Clifford Roche', 'model': 'HomeAssistant Discovery for OctoPrint', 'sw_version': 'HomeAssistant Discovery for OctoPrint 3.6.5', 'connections': []}, 'icon': 'mdi:cancel', 'qos': 0, 'retain': False, 'encoding': 'utf-8', 'enabled_by_default': True, 'payload_press': 'PRESS', 'availability_mode': 'latest'}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Cancel Print'
MQTT entity name starts with the device name in your config {'availability_topic': 'octoprint/mqtt', 'payload_available': 'connected', 'payload_not_available': 'disconnected', 'name': 'OctoPrint Shutdown System', 'unique_id': 'CA6944_SHUTDOWN', 'command_topic': 'octoprint/hassControl/shutdown', 'device': {'identifiers': ['CA6944'], 'name': 'OctoPrint', 'manufacturer': 'Clifford Roche', 'model': 'HomeAssistant Discovery for OctoPrint', 'sw_version': 'HomeAssistant Discovery for OctoPrint 3.6.5', 'connections': []}, 'icon': 'mdi:power', 'qos': 0, 'retain': False, 'encoding': 'utf-8', 'enabled_by_default': True, 'payload_press': 'PRESS', 'availability_mode': 'latest'}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Shutdown System'
MQTT entity name starts with the device name in your config {'availability_topic': 'octoprint/mqtt', 'payload_available': 'connected', 'payload_not_available': 'disconnected', 'name': 'OctoPrint Reboot System', 'unique_id': 'CA6944_REBOOT', 'command_topic': 'octoprint/hassControl/reboot', 'device': {'identifiers': ['CA6944'], 'name': 'OctoPrint', 'manufacturer': 'Clifford Roche', 'model': 'HomeAssistant Discovery for OctoPrint', 'sw_version': 'HomeAssistant Discovery for OctoPrint 3.6.5', 'connections': []}, 'icon': 'mdi:restart-alert', 'qos': 0, 'retain': False, 'encoding': 'utf-8', 'enabled_by_default': True, 'payload_press': 'PRESS', 'availability_mode': 'latest'}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Reboot System'
MQTT entity name starts with the device name in your config {'availability_topic': 'octoprint/mqtt', 'payload_available': 'connected', 'payload_not_available': 'disconnected', 'name': 'OctoPrint Restart Server', 'unique_id': 'CA6944_RESTART', 'command_topic': 'octoprint/hassControl/restart', 'device': {'identifiers': ['CA6944'], 'name': 'OctoPrint', 'manufacturer': 'Clifford Roche', 'model': 'HomeAssistant Discovery for OctoPrint', 'sw_version': 'HomeAssistant Discovery for OctoPrint 3.6.5', 'connections': []}, 'icon': 'mdi:restart', 'qos': 0, 'retain': False, 'encoding': 'utf-8', 'enabled_by_default': True, 'payload_press': 'PRESS', 'availability_mode': 'latest'}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Restart Server'

This PR solves that issue by removing the prefix. I have also edited the names of the entities to follow Home Assistant entity naming guidelines. The first word in the entity name should be capitalized while words that follow should be lowercase (unless it is a brand or the word is capitalized in normal writing). For example Print Time Left has been changed to Print time left.

halfluck commented 1 year ago

I gave this branch a spin but i'm still getting the same errors

https://www.dropbox.com/scl/fi/y9zy6n1c4j8dejcex6iij/ha_log.txt?rlkey=xl57zi9yjppjsk2lal6qqs0br&dl=0

RobertD502 commented 1 year ago

Use a MQTT client to delete the current topic.

halfluck commented 1 year ago

@RobertD502 Thankyou, I used MQTT Explorer to clear all topics and rebooted HA, the same errors are appearing in the log.

RobertD502 commented 1 year ago

Did you delete the topics associated with the MQTT plugin (in Octoprint)? I'd delete those, delete the topic created by this plugin, delete the device in Home Assistant, restart Octoprint, and then restart Home Assistant.

halfluck commented 1 year ago

Ok it looks like most of the errors are gone now it's just down to the "hassControl" and "Camera" ones

RobertD502 commented 1 year ago

Are you referring to the Camera snapshot entity? If so, you shouldn't be getting errors on that since the name has been changed for it as well. There must be something retained that is causing this.

halfluck commented 1 year ago

I tend to agree with you, I'm just going to nuke everything and start from scratch, thanks for your time!

RobertD502 commented 1 year ago

I tend to agree with you, I'm just going to nuke everything and start from scratch, thanks for your time!

Looking at your logs, if you are referring to the entities that have a unique ID that ends with _CAMERA, I don't see any mention of entities being created in this code that sets a unique ID with that suffix. Only one I see is _CAMERA_SNAPSHOT. Is this perhaps originating from another plugin?

halfluck commented 1 year ago

Ok looks like you are onto something. A clean install and I am not getting any errors on one of my instances

RobertD502 commented 1 year ago

Thanks @RobertD502 for this contribution.

@cmroche No problem! Just to add, in the release notes, it might be worthwhile directing users to either delete the current topics or to clear the retained flag as some may not be aware that they have MQTT messages set to be retained in the MQTT plugin. Unless they do this, they will continue to see the error.