Skip to content

Commit c407a20

Browse files
committed
Fix error on numeric entities when no value is available
1 parent ebd604c commit c407a20

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

custom_components/rivian/sensor.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,20 @@ def native_value(self) -> str | None:
115115
if _fn := self.entity_description.value_fn:
116116
return _fn(self.coordinator)
117117

118-
if (val := self._get_value(self.entity_description.field)) is not None:
119-
rval = _fn(val) if (_fn := self.entity_description.value_lambda) else val
120-
if self.device_class == SensorDeviceClass.ENUM and rval not in self.options:
121-
_LOGGER.error(
122-
"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\"'",
123-
self.name,
124-
rval,
125-
self.entity_description.field,
126-
val,
127-
)
128-
self.options.append(rval)
129-
return rval
130-
return STATE_UNAVAILABLE
118+
if (val := self._get_value(self.entity_description.field)) is None:
119+
return STATE_UNAVAILABLE if not self.native_unit_of_measurement else None
120+
121+
rval = _fn(val) if (_fn := self.entity_description.value_lambda) else val
122+
if self.device_class == SensorDeviceClass.ENUM and rval not in self.options:
123+
_LOGGER.error(
124+
"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\"'",
125+
self.name,
126+
rval,
127+
self.entity_description.field,
128+
val,
129+
)
130+
self.options.append(rval)
131+
return rval
131132

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

0 commit comments

Comments
 (0)