Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zappi phase setting select #533

Merged
merged 6 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add zappi phase setting select
    * custom_components/myenergi/select.py:
    * custom_components/myenergi/translations/en.json:
  • Loading branch information
jwillemsen committed May 13, 2024
commit f54de1bbb7dda9494d4a6627e55023ce58c332a3
43 changes: 27 additions & 16 deletions custom_components/myenergi/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

LIBBI_MODE_NAMES = {0: "Stopped", 1: "Normal", 5: "Export"}

ZAPPI_PHASE_SETTING = ["1", "3", "auto"]

ATTR_BOOST_AMOUNT = "amount"
ATTR_BOOST_TIME = "time"
ATTR_BOOST_TARGET = "target"
Expand Down Expand Up @@ -66,6 +68,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
"unlock",
)
devices.append(ZappiChargeModeSelect(coordinator, device, entry))
devices.append(ZappiPhaseSettingSelect(coordinator, device, entry))
elif device.kind == "eddi":
platform.async_register_entity_service(
"myenergi_eddi_boost",
Expand Down Expand Up @@ -113,26 +116,38 @@ def options(self):
return EDDI_MODES


class ZappiChargeModeSelect(MyenergiEntity, SelectEntity):
class ZappiPhaseSettingSelect(MyenergiEntity, SelectEntity):
"""myenergi Sensor class."""

def __init__(self, coordinator, device, config_entry):
super().__init__(coordinator, device, config_entry)
self._attr_icon = "mdi:ev-station"
self._attr_unique_id = f"{self.config_entry.entry_id}-{self.device.serial_number}-phase_setting_select"
self._attr_name = f"myenergi {self.device.name} Phase Setting"
self._attr_translation_key = "phase_setting"
self._attr_options = ZAPPI_PHASE_SETTING

@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.config_entry.entry_id}-{self.device.serial_number}-charge_mode"
def current_option(self):
"""Return the state of the sensor."""
return self.device.num_phases

@property
def name(self):
"""Return the name of the sensor."""
return f"myenergi {self.device.name} Charge Mode"
async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
await self.device.set_phase_setting(option)
self.async_schedule_update_ha_state()

@property
def icon(self):
"""Return the icon of the select."""
return "mdi:ev-station"

class ZappiChargeModeSelect(MyenergiEntity, SelectEntity):
"""myenergi Sensor class."""

def __init__(self, coordinator, device, config_entry):
super().__init__(coordinator, device, config_entry)
self._attr_icon = "mdi:ev-station"
self._attr_unique_id = f"{self.config_entry.entry_id}-{self.device.serial_number}-charge_mode"
self._attr_name = f"myenergi {self.device.name} Charge Mode"
self._attr_translation_key = "phase_setting"
self._attr_options = CHARGE_MODES[1:]

@property
def current_option(self):
Expand All @@ -144,10 +159,6 @@ async def async_select_option(self, option: str) -> None:
await self.device.set_charge_mode(option)
self.async_schedule_update_ha_state()

@property
def options(self):
return CHARGE_MODES[1:]


class LibbiOperatingModeSelect(MyenergiEntity, SelectEntity):
"""myenergi Sensor class."""
Expand Down
11 changes: 11 additions & 0 deletions custom_components/myenergi/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@
}
}
}
},
"entity": {
"select": {
"phase_setting": {
"state" : {
"1" : "1",
"3" : "3",
"auto" : "Automatic"
}
}
}
}
}
Loading