From dbc5109fd839269b84b5a6c841bebae62420268d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 15 Apr 2024 10:42:18 -0500 Subject: [PATCH] Avoid update calls in state writes when attributes are empty (#115624) --- homeassistant/helpers/entity.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index fb071d438b1..20948a7130a 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -1052,8 +1052,10 @@ class Entity( available = self.available # only call self.available once per update cycle state = self._stringify_state(available) if available: - attr.update(self.state_attributes or {}) - attr.update(self.extra_state_attributes or {}) + if state_attributes := self.state_attributes: + attr.update(state_attributes) + if extra_state_attributes := self.extra_state_attributes: + attr.update(extra_state_attributes) if (unit_of_measurement := self.unit_of_measurement) is not None: attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement