mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Move options to SelectEntityDescription in goodwe (#80017)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
458f3d4d13
commit
9d3442055b
@ -14,18 +14,17 @@ from .const import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
INVERTER_OPERATION_MODES = [
|
|
||||||
"General mode",
|
|
||||||
"Off grid mode",
|
|
||||||
"Backup mode",
|
|
||||||
"Eco mode",
|
|
||||||
]
|
|
||||||
|
|
||||||
OPERATION_MODE = SelectEntityDescription(
|
OPERATION_MODE = SelectEntityDescription(
|
||||||
key="operation_mode",
|
key="operation_mode",
|
||||||
name="Inverter operation mode",
|
name="Inverter operation mode",
|
||||||
icon="mdi:solar-power",
|
icon="mdi:solar-power",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
options=[
|
||||||
|
"General mode",
|
||||||
|
"Off grid mode",
|
||||||
|
"Backup mode",
|
||||||
|
"Eco mode",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -45,14 +44,14 @@ async def async_setup_entry(
|
|||||||
# Inverter model does not support this setting
|
# Inverter model does not support this setting
|
||||||
_LOGGER.debug("Could not read inverter operation mode")
|
_LOGGER.debug("Could not read inverter operation mode")
|
||||||
else:
|
else:
|
||||||
if 0 <= active_mode < len(INVERTER_OPERATION_MODES):
|
if (options := OPERATION_MODE.options) and 0 <= active_mode < len(options):
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
InverterOperationModeEntity(
|
InverterOperationModeEntity(
|
||||||
device_info,
|
device_info,
|
||||||
OPERATION_MODE,
|
OPERATION_MODE,
|
||||||
inverter,
|
inverter,
|
||||||
INVERTER_OPERATION_MODES[active_mode],
|
options[active_mode],
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -74,12 +73,11 @@ class InverterOperationModeEntity(SelectEntity):
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{DOMAIN}-{description.key}-{inverter.serial_number}"
|
self._attr_unique_id = f"{DOMAIN}-{description.key}-{inverter.serial_number}"
|
||||||
self._attr_device_info = device_info
|
self._attr_device_info = device_info
|
||||||
self._attr_options = INVERTER_OPERATION_MODES
|
|
||||||
self._attr_current_option = current_mode
|
self._attr_current_option = current_mode
|
||||||
self._inverter: Inverter = inverter
|
self._inverter: Inverter = inverter
|
||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Change the selected option."""
|
"""Change the selected option."""
|
||||||
await self._inverter.set_operation_mode(INVERTER_OPERATION_MODES.index(option))
|
await self._inverter.set_operation_mode(self.options.index(option))
|
||||||
self._attr_current_option = option
|
self._attr_current_option = option
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user