Skip to content

Commit

Permalink
Fix error on numeric entities when no value is available
Browse files Browse the repository at this point in the history
  • Loading branch information
natekspencer committed Dec 6, 2023
1 parent ebd604c commit c407a20
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions custom_components/rivian/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,20 @@ def native_value(self) -> str | None:
if _fn := self.entity_description.value_fn:
return _fn(self.coordinator)

if (val := self._get_value(self.entity_description.field)) is not None:
rval = _fn(val) if (_fn := self.entity_description.value_lambda) else val
if self.device_class == SensorDeviceClass.ENUM and rval not in self.options:
_LOGGER.error(
"Sensor %s provides state value '%s', which is not in the list of known options. Please consider opening an issue at https://github.com/bretterer/home-assistant-rivian/issues with the following info: 'field: \"%s\" / value: \"%s\"'",
self.name,
rval,
self.entity_description.field,
val,
)
self.options.append(rval)
return rval
return STATE_UNAVAILABLE
if (val := self._get_value(self.entity_description.field)) is None:
return STATE_UNAVAILABLE if not self.native_unit_of_measurement else None

rval = _fn(val) if (_fn := self.entity_description.value_lambda) else val
if self.device_class == SensorDeviceClass.ENUM and rval not in self.options:
_LOGGER.error(
"Sensor %s provides state value '%s', which is not in the list of known options. Please consider opening an issue at https://github.com/bretterer/home-assistant-rivian/issues with the following info: 'field: \"%s\" / value: \"%s\"'",
self.name,
rval,
self.entity_description.field,
val,
)
self.options.append(rval)
return rval

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
Expand Down

0 comments on commit c407a20

Please sign in to comment.