Handle empty strings for ESPHome UOMs (#96556)

This commit is contained in:
J. Nick Koston 2023-07-14 12:14:32 -10:00 committed by GitHub
parent 72458b6672
commit b77de2abaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 4 deletions

View file

@ -63,7 +63,10 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
self._attr_native_min_value = static_info.min_value
self._attr_native_max_value = static_info.max_value
self._attr_native_step = static_info.step
self._attr_native_unit_of_measurement = static_info.unit_of_measurement
# protobuf doesn't support nullable strings so we need to check
# if the string is empty
if unit_of_measurement := static_info.unit_of_measurement:
self._attr_native_unit_of_measurement = unit_of_measurement
if mode := static_info.mode:
self._attr_mode = NUMBER_MODES.from_esphome(mode)
else: