diff --git a/homeassistant/components/wled/switch.py b/homeassistant/components/wled/switch.py index 9f241756e90..4a36fededbe 100644 --- a/homeassistant/components/wled/switch.py +++ b/homeassistant/components/wled/switch.py @@ -65,10 +65,11 @@ class WLEDNightlightSwitch(WLEDEntity, SwitchEntity): @property def extra_state_attributes(self) -> dict[str, Any] | None: """Return the state attributes of the entity.""" + state = self.coordinator.data.state return { - ATTR_DURATION: self.coordinator.data.state.nightlight.duration, - ATTR_FADE: self.coordinator.data.state.nightlight.fade, - ATTR_TARGET_BRIGHTNESS: self.coordinator.data.state.nightlight.target_brightness, + ATTR_DURATION: state.nightlight.duration, + ATTR_FADE: state.nightlight.fade, + ATTR_TARGET_BRIGHTNESS: state.nightlight.target_brightness, } @property diff --git a/tests/components/wled/test_diagnostics.py b/tests/components/wled/test_diagnostics.py index 8f086331f8f..3588ecdb498 100644 --- a/tests/components/wled/test_diagnostics.py +++ b/tests/components/wled/test_diagnostics.py @@ -50,7 +50,10 @@ async def test_diagnostics( "brightness": 127, "nightlight": { "__type": "", - "repr": "Nightlight(duration=60, fade=True, on=False, mode=, target_brightness=0)", + "repr": ( + "Nightlight(duration=60, fade=True, on=False," + " mode=, target_brightness=0)" + ), }, "on": True, "playlist": -1, @@ -58,11 +61,31 @@ async def test_diagnostics( "segments": [ { "__type": "", - "repr": "Segment(brightness=127, clones=-1, color_primary=(255, 159, 0), color_secondary=(0, 0, 0), color_tertiary=(0, 0, 0), effect=Effect(effect_id=0, name='Solid'), intensity=128, length=20, on=True, palette=Palette(name='Default', palette_id=0), reverse=False, segment_id=0, selected=True, speed=32, start=0, stop=19)", + "repr": ( + "Segment(brightness=127, clones=-1," + " color_primary=(255, 159, 0)," + " color_secondary=(0, 0, 0)," + " color_tertiary=(0, 0, 0)," + " effect=Effect(effect_id=0, name='Solid')," + " intensity=128, length=20, on=True," + " palette=Palette(name='Default', palette_id=0)," + " reverse=False, segment_id=0, selected=True," + " speed=32, start=0, stop=19)" + ), }, { "__type": "", - "repr": "Segment(brightness=127, clones=-1, color_primary=(0, 255, 123), color_secondary=(0, 0, 0), color_tertiary=(0, 0, 0), effect=Effect(effect_id=1, name='Blink'), intensity=64, length=10, on=True, palette=Palette(name='Random Cycle', palette_id=1), reverse=True, segment_id=1, selected=True, speed=16, start=20, stop=30)", + "repr": ( + "Segment(brightness=127, clones=-1," + " color_primary=(0, 255, 123)," + " color_secondary=(0, 0, 0)," + " color_tertiary=(0, 0, 0)," + " effect=Effect(effect_id=1, name='Blink')," + " intensity=64, length=10, on=True," + " palette=Palette(name='Random Cycle', palette_id=1)," + " reverse=True, segment_id=1, selected=True," + " speed=16, start=20, stop=30)" + ), }, ], "sync": {