-
Notifications
You must be signed in to change notification settings - Fork 27
Improve Charger Support/Use & more QOL #243
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fc3774a
Improve chargers
Poshy163 609b3d2
Add SMILE-EVCS7 as a known inverter
Poshy163 fa61a13
Add currency diagnostic sensor, and only pass EV charger sensor if no…
Poshy163 295c64a
Fix current diagnostic not working, and also make pev unavalible if n…
Poshy163 5a8ae6d
Add One-time startup cleanup migration for ev entties that dont exist…
Poshy163 e55aa03
remove fallback
Poshy163 96dea06
Preserve internal flags in config flow during option saves
Poshy163 56be07a
Bump version to 0.8.4
Poshy163 d5f5c44
Extract and centralize `build_inverter_device_info` and `build_ev_cha…
Poshy163 cbef404
Simplify `build_inverter_device_info` and `build_ev_charger_device_in…
Poshy163 911f08b
Refactor to pass `coordinator` to device info builders, adjust EV cha…
Poshy163 dfe2a4a
Remove unused coordinator param from device info builders and align a…
Poshy163 a2f7a86
Gate EV entity cleanup on cloud_available; use TOTAL state_class for …
Poshy163 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| """Binary sensor platform for AlphaESS integration.""" | ||
| from typing import List | ||
| import logging | ||
|
|
||
| from homeassistant.components.binary_sensor import BinarySensorEntity | ||
| from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
|
||
| from .const import ( | ||
| DOMAIN, | ||
| CONF_SERIAL_NUMBER, | ||
| SUBENTRY_TYPE_INVERTER, | ||
| SUBENTRY_TYPE_EV_CHARGER, | ||
| CONF_PARENT_INVERTER, | ||
| ) | ||
| from .coordinator import AlphaESSDataUpdateCoordinator | ||
| from .sensorlist import EV_CHARGER_BINARY_SENSORS | ||
| from .device import build_ev_charger_device_info | ||
|
|
||
| _LOGGER: logging.Logger = logging.getLogger(__package__) | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, entry, async_add_entities) -> None: | ||
| """Set up EV charger readiness binary sensors.""" | ||
| coordinator: AlphaESSDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] | ||
|
|
||
| ev_binary_supported_states = { | ||
| description.key: description for description in EV_CHARGER_BINARY_SENSORS | ||
| } | ||
|
|
||
| for subentry in entry.subentries.values(): | ||
| if subentry.subentry_type == SUBENTRY_TYPE_INVERTER: | ||
| serial = subentry.data.get(CONF_SERIAL_NUMBER) | ||
| if not serial or serial not in coordinator.data: | ||
| continue | ||
|
|
||
| data = coordinator.data[serial] | ||
| ev_charger = data.get("EV Charger S/N") | ||
| if not ev_charger: | ||
| continue | ||
|
|
||
| ev_subentry_serials = { | ||
| sub.data.get(CONF_SERIAL_NUMBER) | ||
| for sub in entry.subentries.values() | ||
| if sub.subentry_type == SUBENTRY_TYPE_EV_CHARGER | ||
| } | ||
| if ev_charger in ev_subentry_serials: | ||
| continue | ||
|
|
||
| ev_device_info = build_ev_charger_device_info(data) | ||
| ev_entities: List[BinarySensorEntity] = [] | ||
| for description in ev_binary_supported_states.values(): | ||
| ev_entities.append( | ||
| AlphaEVReadinessBinarySensor( | ||
| coordinator, | ||
| serial, | ||
| entry, | ||
| description, | ||
| ev_serial=ev_charger, | ||
| device_info=ev_device_info, | ||
| ) | ||
| ) | ||
|
|
||
| if ev_entities: | ||
| async_add_entities(ev_entities, config_subentry_id=subentry.subentry_id) | ||
|
|
||
| elif subentry.subentry_type == SUBENTRY_TYPE_EV_CHARGER: | ||
| parent_serial = subentry.data.get(CONF_PARENT_INVERTER) | ||
| if not parent_serial or parent_serial not in coordinator.data: | ||
| continue | ||
|
|
||
| data = coordinator.data[parent_serial] | ||
| ev_charger = data.get("EV Charger S/N") | ||
| if not ev_charger: | ||
| continue | ||
|
|
||
| ev_device_info = build_ev_charger_device_info(data) | ||
| ev_entities: List[BinarySensorEntity] = [] | ||
| for description in ev_binary_supported_states.values(): | ||
| ev_entities.append( | ||
| AlphaEVReadinessBinarySensor( | ||
| coordinator, | ||
| parent_serial, | ||
| entry, | ||
| description, | ||
| ev_serial=ev_charger, | ||
| device_info=ev_device_info, | ||
| ) | ||
| ) | ||
|
|
||
| if ev_entities: | ||
| async_add_entities(ev_entities, config_subentry_id=subentry.subentry_id) | ||
|
|
||
|
|
||
| class AlphaEVReadinessBinarySensor(CoordinatorEntity, BinarySensorEntity): | ||
| """Readiness sensor for EV charger start/stop commands.""" | ||
|
|
||
| def __init__(self, coordinator, serial, config, description, ev_serial=None, device_info=None): | ||
| super().__init__(coordinator) | ||
| self._coordinator = coordinator | ||
| self._serial = serial | ||
| self._config = config | ||
| self._description = description | ||
| self._ev_serial = ev_serial | ||
| self._name = description.name | ||
| self._icon = description.icon | ||
| self._entity_category = description.entity_category | ||
| self._direction = description.direction | ||
|
|
||
| if device_info: | ||
| self._attr_device_info = device_info | ||
|
|
||
| @property | ||
| def is_on(self) -> bool | None: | ||
| """Return readiness to execute EV command.""" | ||
| if self._direction is None: | ||
| return None | ||
|
|
||
| if self._coordinator.get_ev_charger_status_raw(self._serial) is None: | ||
| return None | ||
|
|
||
| return self._coordinator.can_control_ev(self._serial, self._direction) | ||
|
|
||
| @property | ||
| def available(self) -> bool: | ||
| """Readiness sensors require cloud EV data.""" | ||
| if not self.coordinator.last_update_success: | ||
| return False | ||
| if not self._coordinator.cloud_available: | ||
| return False | ||
|
|
||
| serial_data = self._coordinator.data.get(self._serial, {}) | ||
| return serial_data.get("EV Charger S/N") is not None | ||
|
|
||
| @property | ||
| def unique_id(self): | ||
| return f"{self._config.entry_id}_{self._serial} - {self._name}" | ||
|
|
||
| @property | ||
| def name(self): | ||
| return f"{self._name}" | ||
|
|
||
| @property | ||
| def suggested_object_id(self): | ||
| return f"{self._serial} {self._name}" | ||
|
|
||
| @property | ||
| def entity_category(self): | ||
| return self._entity_category | ||
|
|
||
| @property | ||
| def icon(self): | ||
| return self._icon | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
binary_sensor.pyimports_build_ev_charger_device_infofromsensor.py, but the leading underscore indicates it is a private helper. Since it’s now used across modules, consider moving it to a shared utility module (or renaming it without the underscore) to make the intended public usage explicit and avoid future refactors accidentally breaking the binary sensor platform.