From 6d82ae1891fba1ac85fc31708c1aa130026b3dc8 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 8 Feb 2024 15:56:02 +0100 Subject: [PATCH] Avoid key_error with non-defined fan_mode. --- homeassistant/components/modbus/climate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/modbus/climate.py b/homeassistant/components/modbus/climate.py index 637478fffd4d0d..d31323a27e9c78 100644 --- a/homeassistant/components/modbus/climate.py +++ b/homeassistant/components/modbus/climate.py @@ -364,7 +364,9 @@ async def async_update(self, now: datetime | None = None) -> None: # Translate the value received if fan_mode is not None: - self._attr_fan_mode = self._fan_mode_mapping_from_modbus[int(fan_mode)] + self._attr_fan_mode = self._fan_mode_mapping_from_modbus.get( + int(fan_mode), self._attr_fan_mode + ) # Read the on/off register if defined. If the value in this # register is "OFF", it will take precedence over the value