Reduce multiple calls to calculate sensor unit in tplink (#124606)

accessing unit on the feature is not cached and it had
to be looked up every time
This commit is contained in:
J. Nick Koston 2024-08-26 01:49:26 -10:00 committed by GitHub
parent 16231da5ef
commit 743df84569
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -154,7 +154,5 @@ class TPLinkSensorEntity(CoordinatedTPLinkFeatureEntity, SensorEntity):
self._attr_native_value = value
# Map to homeassistant units and fallback to upstream one if none found
if self._feature.unit is not None:
self._attr_native_unit_of_measurement = UNIT_MAPPING.get(
self._feature.unit, self._feature.unit
)
if (unit := self._feature.unit) is not None:
self._attr_native_unit_of_measurement = UNIT_MAPPING.get(unit, unit)