|
35 | 35 | from homeassistant.helpers import config_validation as cv |
36 | 36 | from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback |
37 | 37 | from homeassistant.helpers.event import async_call_later |
38 | | -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue |
39 | 38 | from homeassistant.helpers.service_info.mqtt import ReceivePayloadType |
40 | 39 | from homeassistant.helpers.typing import ConfigType, VolSchemaType |
41 | 40 | from homeassistant.util import dt as dt_util |
|
48 | 47 | CONF_OPTIONS, |
49 | 48 | CONF_STATE_TOPIC, |
50 | 49 | CONF_SUGGESTED_DISPLAY_PRECISION, |
51 | | - DOMAIN, |
52 | 50 | PAYLOAD_NONE, |
53 | 51 | ) |
54 | 52 | from .entity import MqttAvailabilityMixin, MqttEntity, async_setup_entity_entry_helper |
@@ -138,12 +136,9 @@ def validate_sensor_state_and_device_class_config(config: ConfigType) -> ConfigT |
138 | 136 | device_class in DEVICE_CLASS_UNITS |
139 | 137 | and unit_of_measurement not in DEVICE_CLASS_UNITS[device_class] |
140 | 138 | ): |
141 | | - _LOGGER.warning( |
142 | | - "The unit of measurement `%s` is not valid " |
143 | | - "together with device class `%s`. " |
144 | | - "this will stop working in HA Core 2025.7.0", |
145 | | - unit_of_measurement, |
146 | | - device_class, |
| 139 | + raise vol.Invalid( |
| 140 | + f"The unit of measurement `{unit_of_measurement}` is not valid " |
| 141 | + f"together with device class `{device_class}`", |
147 | 142 | ) |
148 | 143 |
|
149 | 144 | return config |
@@ -194,40 +189,8 @@ class MqttSensor(MqttEntity, RestoreSensor): |
194 | 189 | None |
195 | 190 | ) |
196 | 191 |
|
197 | | - @callback |
198 | | - def async_check_uom(self) -> None: |
199 | | - """Check if the unit of measurement is valid with the device class.""" |
200 | | - if ( |
201 | | - self._discovery_data is not None |
202 | | - or self.device_class is None |
203 | | - or self.native_unit_of_measurement is None |
204 | | - ): |
205 | | - return |
206 | | - if ( |
207 | | - self.device_class in DEVICE_CLASS_UNITS |
208 | | - and self.native_unit_of_measurement |
209 | | - not in DEVICE_CLASS_UNITS[self.device_class] |
210 | | - ): |
211 | | - async_create_issue( |
212 | | - self.hass, |
213 | | - DOMAIN, |
214 | | - self.entity_id, |
215 | | - issue_domain=sensor.DOMAIN, |
216 | | - is_fixable=False, |
217 | | - severity=IssueSeverity.WARNING, |
218 | | - learn_more_url=URL_DOCS_SUPPORTED_SENSOR_UOM, |
219 | | - translation_placeholders={ |
220 | | - "uom": self.native_unit_of_measurement, |
221 | | - "device_class": self.device_class.value, |
222 | | - "entity_id": self.entity_id, |
223 | | - }, |
224 | | - translation_key="invalid_unit_of_measurement", |
225 | | - breaks_in_ha_version="2025.7.0", |
226 | | - ) |
227 | | - |
228 | 192 | async def mqtt_async_added_to_hass(self) -> None: |
229 | 193 | """Restore state for entities with expire_after set.""" |
230 | | - self.async_check_uom() |
231 | 194 | last_state: State | None |
232 | 195 | last_sensor_data: SensorExtraStoredData | None |
233 | 196 | if ( |
|
0 commit comments