-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Add amperage limit number to JuiceNet #71716
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,93 @@ | ||
| """Support for controlling juicenet/juicepoint/juicebox based EVSE numbers.""" | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from pyjuicenet import Api, Charger | ||
|
|
||
| from homeassistant.components.number import NumberEntity, NumberEntityDescription | ||
| from homeassistant.components.number.const import DEFAULT_MAX_VALUE | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
| from homeassistant.helpers.update_coordinator import DataUpdateCoordinator | ||
|
|
||
| from .const import DOMAIN, JUICENET_API, JUICENET_COORDINATOR | ||
| from .entity import JuiceNetDevice | ||
|
|
||
|
|
||
| @dataclass | ||
| class JuiceNetNumberEntityDescription(NumberEntityDescription): | ||
| """An entity description for a JuiceNetNumber.""" | ||
|
|
||
| setter_key: str | None = None | ||
| max_value_key: str | None = None | ||
|
|
||
|
|
||
| NUMBER_TYPES: tuple[JuiceNetNumberEntityDescription, ...] = ( | ||
| JuiceNetNumberEntityDescription( | ||
| name="Amperage Limit", | ||
| key="current_charging_amperage_limit", | ||
| min_value=6, | ||
| max_value_key="max_charging_amperage", | ||
| step=1, | ||
| setter_key="set_charging_amperage_limit", | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| config_entry: ConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ) -> None: | ||
| """Set up the JuiceNet Numbers.""" | ||
| juicenet_data = hass.data[DOMAIN][config_entry.entry_id] | ||
| api: Api = juicenet_data[JUICENET_API] | ||
| coordinator = juicenet_data[JUICENET_COORDINATOR] | ||
|
|
||
| entities = [ | ||
| JuiceNetNumber(device, description, coordinator) | ||
| for device in api.devices | ||
| for description in NUMBER_TYPES | ||
| ] | ||
| async_add_entities(entities) | ||
|
|
||
|
|
||
| class JuiceNetNumber(JuiceNetDevice, NumberEntity): | ||
| """Implementation of a JuiceNet number.""" | ||
|
|
||
| entity_description: JuiceNetNumberEntityDescription | ||
|
|
||
| def __init__( | ||
| self, | ||
| device: Charger, | ||
| description: JuiceNetNumberEntityDescription, | ||
| coordinator: DataUpdateCoordinator, | ||
| ) -> None: | ||
| """Initialise the number.""" | ||
| super().__init__(device, description.key, coordinator) | ||
| self.entity_description = description | ||
|
|
||
| self._attr_name = f"{self.device.name} {description.name}" | ||
|
|
||
| @property | ||
| def value(self) -> float | None: | ||
| """Return the value of the entity.""" | ||
| return getattr(self.device, self.entity_description.key, None) | ||
|
|
||
| @property | ||
| def max_value(self) -> float: | ||
| """Return the maximum value.""" | ||
| if self.entity_description.max_value_key is not None: | ||
| return getattr(self.device, self.entity_description.max_value_key) | ||
| if self.entity_description.max_value is not None: | ||
| return self.entity_description.max_value | ||
| return DEFAULT_MAX_VALUE | ||
|
|
||
| async def async_set_value(self, value: float) -> None: | ||
| """Update the current value.""" | ||
| if self.entity_description.setter_key is not None: | ||
| await getattr(self.device, self.entity_description.setter_key)(value) | ||
| else: | ||
| raise NotImplementedError | ||
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.
Uh oh!
There was an error while loading. Please reload this page.