Additional processing is required by users of the module to use numerical values presented as strings. This module should convert the text strings to numerical types.
Example from HomeAssistant:
def get_current_value(self):
"""Get raw value from the coordinator."""
if isinstance(data := self.coordinator.data, dict):
value = data.get(self.vin)[VEHICLE_STATUS].get(self.entity_description.key)
if value in sc.BAD_SENSOR_VALUES:
value = None
if isinstance(value, str):
if "." in value:
value = float(value)
elif value.isdigit():
value = int(value)
_LOGGER.debug("Raw value for %s: %s", self._attr_name, value)
return value
Ideally, this code should be simplified to without any adverse behavior:
def get_current_value(self):
"""Get raw value from the coordinator."""
if isinstance(data := self.coordinator.data, dict):
value = data.get(self.vin)[VEHICLE_STATUS].get(self.entity_description.key)
_LOGGER.debug("Raw value for %s: %s", self._attr_name, value)
return value
Additional processing is required by users of the module to use numerical values presented as strings. This module should convert the text strings to numerical types.
Example from HomeAssistant:
Ideally, this code should be simplified to without any adverse behavior: