1 """GoodWe PV inverter selection settings entities."""
5 from goodwe
import Inverter, InverterError, OperationMode
14 from .const
import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER
16 _LOGGER = logging.getLogger(__name__)
19 _MODE_TO_OPTION: dict[OperationMode, str] = {
20 OperationMode.GENERAL:
"general",
21 OperationMode.OFF_GRID:
"off_grid",
22 OperationMode.BACKUP:
"backup",
23 OperationMode.ECO:
"eco",
24 OperationMode.PEAK_SHAVING:
"peak_shaving",
25 OperationMode.ECO_CHARGE:
"eco_charge",
26 OperationMode.ECO_DISCHARGE:
"eco_discharge",
29 _OPTION_TO_MODE: dict[str, OperationMode] = {
30 value: key
for key, value
in _MODE_TO_OPTION.items()
35 entity_category=EntityCategory.CONFIG,
36 translation_key=
"operation_mode",
42 config_entry: ConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up the inverter select entities from a config entry."""
46 inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
47 device_info = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE_INFO]
49 supported_modes = await inverter.get_operation_modes(
False)
52 active_mode = await inverter.get_operation_mode()
53 except (InverterError, ValueError):
55 _LOGGER.debug(
"Could not read inverter operation mode")
63 [v
for k, v
in _MODE_TO_OPTION.items()
if k
in supported_modes],
64 _MODE_TO_OPTION[active_mode],
71 """Entity representing the inverter operation mode."""
73 _attr_should_poll =
False
74 _attr_has_entity_name =
True
78 device_info: DeviceInfo,
79 description: SelectEntityDescription,
81 supported_options: list[str],
84 """Initialize the inverter operation mode setting entity."""
86 self.
_attr_unique_id_attr_unique_id = f
"{DOMAIN}-{description.key}-{inverter.serial_number}"
90 self._inverter: Inverter = inverter
93 """Get the current value from inverter."""
94 value = await self._inverter.get_operation_mode()
98 """Change the selected option."""
99 await self._inverter.set_operation_mode(_OPTION_TO_MODE[option])
None async_select_option(self, str option)
None __init__(self, DeviceInfo device_info, SelectEntityDescription description, Inverter inverter, list[str] supported_options, str current_mode)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)