Skip to content

Commit 74a81b4

Browse files
committed
Fix select platform bug #28
1 parent 452b5f5 commit 74a81b4

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

custom_components/wemportal/select.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1010
from homeassistant.helpers.update_coordinator import CoordinatorEntity
1111

12-
from .const import DOMAIN
12+
from .const import DOMAIN, _LOGGER
1313
from . import get_wemportal_unique_id
1414

1515

@@ -116,11 +116,19 @@ def options(self) -> list[str]:
116116
@property
117117
def current_option(self) -> str:
118118
"""Return the current option."""
119-
return self._options_names[
120-
self._options.index(
121-
self.coordinator.data[self._device_id][self._name]["value"]
122-
)
123-
]
119+
try:
120+
options = self._options_names[
121+
self._options.index(
122+
self.coordinator.data[self._device_id][self._name]["value"]
123+
)
124+
]
125+
if options:
126+
return options
127+
except KeyError:
128+
_LOGGER.warning("Can't find %s", self._unique_id)
129+
_LOGGER.debug("Sensor data %s", self.coordinator.data)
130+
131+
return None
124132

125133
async def async_added_to_hass(self):
126134
"""When entity is added to hass."""

0 commit comments

Comments
 (0)