Skip to content

Commit 739157e

Browse files
authored
Simplify availability property in WLED (home-assistant#157800)
Co-authored-by: mik-laj <[email protected]>
1 parent 267aa1a commit 739157e

File tree

5 files changed

+12
-28
lines changed

5 files changed

+12
-28
lines changed

homeassistant/components/wled/light.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,9 @@ def __init__(
150150
@property
151151
def available(self) -> bool:
152152
"""Return True if entity is available."""
153-
try:
154-
self.coordinator.data.state.segments[self._segment]
155-
except KeyError:
156-
return False
157-
158-
return super().available
153+
return (
154+
super().available and self._segment in self.coordinator.data.state.segments
155+
)
159156

160157
@property
161158
def rgb_color(self) -> tuple[int, int, int] | None:

homeassistant/components/wled/number.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,9 @@ def __init__(
9797
@property
9898
def available(self) -> bool:
9999
"""Return True if entity is available."""
100-
try:
101-
self.coordinator.data.state.segments[self._segment]
102-
except KeyError:
103-
return False
104-
105-
return super().available
100+
return (
101+
super().available and self._segment in self.coordinator.data.state.segments
102+
)
106103

107104
@property
108105
def native_value(self) -> float | None:

homeassistant/components/wled/quality_scale.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ rules:
3131
config-entry-unloading: done
3232
docs-configuration-parameters: done
3333
docs-installation-parameters: todo
34-
entity-unavailable:
35-
status: todo
36-
comment: |
37-
The WLEDSegmentLight.available property can just be an if .. in .. check
3834
integration-owner: done
3935
log-when-unavailable: done
4036
parallel-updates: done

homeassistant/components/wled/select.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,9 @@ def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None
173173
@property
174174
def available(self) -> bool:
175175
"""Return True if entity is available."""
176-
try:
177-
self.coordinator.data.state.segments[self._segment]
178-
except KeyError:
179-
return False
180-
181-
return super().available
176+
return (
177+
super().available and self._segment in self.coordinator.data.state.segments
178+
)
182179

183180
@property
184181
def current_option(self) -> str | None:

homeassistant/components/wled/switch.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,9 @@ def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None
167167
@property
168168
def available(self) -> bool:
169169
"""Return True if entity is available."""
170-
try:
171-
self.coordinator.data.state.segments[self._segment]
172-
except KeyError:
173-
return False
174-
175-
return super().available
170+
return (
171+
super().available and self._segment in self.coordinator.data.state.segments
172+
)
176173

177174
@property
178175
def is_on(self) -> bool:

0 commit comments

Comments
 (0)