-
-
Notifications
You must be signed in to change notification settings - Fork 101
Add number platform using slider (input_number) #124
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
29 commits
Select commit
Hold shift + click to select a range
5f17a52
introduce the Metric class
24968d3
fix errors
09b9765
imake extra attr a metric property
dae06db
fix unreachable code
9df2697
Merge pull request #27 from lbbrhzn/main
drc38 4cf5636
Revert "Merge branch 'main' into main"
drc38 def6499
Merge pull request #28 from lbbrhzn/metric_class
drc38 d3e5695
Update tests.yaml
drc38 988b6d7
Merge remote-tracking branch 'upstream/main' into main
drc38 b8db4a4
Merge branch 'main' of https://github.com/drc38/ocpp into main
drc38 3e5832c
use flags for supported features
drc38 48901e3
fix enum reference
drc38 b2659be
Merge pull request #29 from drc38/supported-features
drc38 b1f7d0a
initial addition of slider
drc38 43aabcd
Merge branch 'main' into slider
drc38 9c5609c
add slider to platforms
drc38 26700ed
Merge branch 'slider' of https://github.com/drc38/ocpp into slider
drc38 443f657
fix enums
drc38 0dbe450
rename to input_number
drc38 4408bea
incorporate @lbbrhzn edits
drc38 d554162
add number slider test
drc38 1ec975d
update test service call
drc38 1c1ea1e
fix call
drc38 0c95b3a
fix entity_id
drc38 37e2281
fix set_charge_rate call
drc38 3519d60
add self.name
drc38 ac9adda
change to self._name
drc38 88505d7
check SMART profile supported, tidy refs
drc38 a5c8484
change to bitwise compare
drc38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ on: | |
- master | ||
- dev | ||
pull_request: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
env: | ||
DEFAULT_PYTHON: 3.9 | ||
|
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,74 @@ | ||
"""Number platform for ocpp.""" | ||
from homeassistant.components.input_number import InputNumber | ||
import voluptuous as vol | ||
|
||
from .api import CentralSystem | ||
from .const import CONF_CPID, DEFAULT_CPID, DOMAIN, NUMBERS | ||
from .enums import Profiles | ||
|
||
|
||
async def async_setup_entry(hass, entry, async_add_devices): | ||
"""Configure the number platform.""" | ||
central_system = hass.data[DOMAIN][entry.entry_id] | ||
cp_id = entry.data.get(CONF_CPID, DEFAULT_CPID) | ||
|
||
entities = [] | ||
|
||
for cfg in NUMBERS: | ||
entities.append(Number(central_system, cp_id, cfg)) | ||
|
||
async_add_devices(entities, False) | ||
|
||
|
||
class Number(InputNumber): | ||
"""Individual slider for setting charge rate.""" | ||
|
||
def __init__(self, central_system: CentralSystem, cp_id: str, config: dict): | ||
"""Initialize a Number instance.""" | ||
super().__init__(config) | ||
self.cp_id = cp_id | ||
self.central_system = central_system | ||
self.id = ".".join(["number", self.cp_id, config["name"]]) | ||
self._name = ".".join([self.cp_id, config["name"]]) | ||
self.entity_id = "number." + "_".join([self.cp_id, config["name"]]) | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return the unique id of this entity.""" | ||
return self.id | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of this entity.""" | ||
return self._name | ||
|
||
@property | ||
def available(self) -> bool: | ||
"""Return if entity is available.""" | ||
if not ( | ||
Profiles.SMART & self.central_system.get_supported_features(self.cp_id) | ||
): | ||
return False | ||
return self.central_system.get_available(self.cp_id) # type: ignore [no-any-return] | ||
|
||
@property | ||
def device_info(self): | ||
"""Return device information.""" | ||
return { | ||
"identifiers": {(DOMAIN, self.cp_id)}, | ||
"via_device": (DOMAIN, self.central_system.id), | ||
} | ||
|
||
async def async_set_value(self, value): | ||
"""Set new value.""" | ||
num_value = float(value) | ||
|
||
if num_value < self._minimum or num_value > self._maximum: | ||
raise vol.Invalid( | ||
f"Invalid value for {self.entity_id}: {value} (range {self._minimum} - {self._maximum})" | ||
) | ||
|
||
resp = await self.central_system.set_max_charge_rate_amps(self.cp_id, num_value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to make the service call parameterizable. Maybe hook it up to a Metric, and let the charger subscribe to notifications? I guess the Number entity should also subscribe to the Metric, to make the slider revert to the previous value if the new value cannot be set. |
||
if resp: | ||
self._current_value = num_value | ||
self.async_write_ha_state() |
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
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.
This will disable the slider when the charge point is not available. From usability point of view it would be nice if you could set the slider value when then charge point is not available. They should then be applied on (re-)connect. I think this should be possible by connecting to a Metric.