Is it possible to issue an error/alert from a custom integration?

I’m trying to help another developer decide upon a weird UX problem on a custom integration, and it looks like the best way is to fire a warning to the user when they do a specific action. Is that possible?

He thinks the only way is to fire a persistent notification, which might be too much, and I couldn’t find a single page on the Development wiki on how to surface errors to the user… I’m thinking something like those bottom corner notices you get when you restart HA, for instance.

That is, unless you have a better idea for the following scenario: there’s a switch that should only be used when the device is on a specific mode; currently, that switch gets disabled, what causes users to think it’s actually broken. My suggestion is to leave it enabled, but if the user tries to toggle it, they’ll get an explanatory warning and the switch will do nothing.

If you raise a HomeAssistantError, it will show in a toast notification (the ones on the bottom left). This can be imported from homeassistant.exceptions

Note, it also logs this as an error in the HA logs.