From 743df84569eb66fce9663988cc1f26550996c52b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 26 Aug 2024 01:49:26 -1000 Subject: [PATCH] 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 --- homeassistant/components/tplink/sensor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/tplink/sensor.py b/homeassistant/components/tplink/sensor.py index 3da414d74d3..1307079937f 100644 --- a/homeassistant/components/tplink/sensor.py +++ b/homeassistant/components/tplink/sensor.py @@ -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)