-
Notifications
You must be signed in to change notification settings - Fork 75
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 IQ Battery power charge and discharge #207
Open
isottipietro
wants to merge
1
commit into
briancmpbll:main
Choose a base branch
from
isottipietro:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−1
Open
Changes from all commits
Commits
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 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 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 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 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 |
---|---|---|
|
@@ -60,6 +60,22 @@ async def async_setup_entry( | |
) | ||
) | ||
|
||
elif (sensor_description.key == "batteries_power"): | ||
if (coordinator.data.get("batteries_power") is not None): | ||
for battery in coordinator.data["batteries_power"]: | ||
entity_name = f"{name} {sensor_description.name} {battery}" | ||
serial_number = battery | ||
entities.append( | ||
EnvoyBatteryPowerEntity( | ||
sensor_description, | ||
entity_name, | ||
name, | ||
config_entry.unique_id, | ||
serial_number, | ||
coordinator | ||
) | ||
) | ||
|
||
elif (sensor_description.key == "current_battery_capacity"): | ||
if (coordinator.data.get("batteries") is not None): | ||
battery_capacity_entity = TotalBatteryCapacityEntity( | ||
|
@@ -316,13 +332,61 @@ def extra_state_attributes(self): | |
last_reported = strftime( | ||
"%Y-%m-%d %H:%M:%S", localtime(battery.get("last_rpt_date")) | ||
) | ||
bmu_fw_version = battery.get("bmu_fw_version") | ||
zigbee_dongle_fw_version = battery.get("zigbee_dongle_fw_version") | ||
comm_level_sub_ghz = battery.get("comm_level_sub_ghz") | ||
comm_level_2_4_ghz = battery.get("comm_level_2_4_ghz") | ||
return { | ||
"last_reported": last_reported, | ||
"capacity": battery.get("encharge_capacity") | ||
"capacity": battery.get("encharge_capacity"), | ||
"bmu_fw_version": bmu_fw_version, | ||
"comm_level_sub_ghz": comm_level_sub_ghz, | ||
"comm_level_2_4_ghz": comm_level_2_4_ghz | ||
} | ||
|
||
return None | ||
|
||
class EnvoyBatteryPowerEntity(CoordinatedEnvoyEntity): | ||
"""Envoy battery power entity.""" | ||
|
||
def __init__( | ||
self, | ||
description, | ||
name, | ||
device_name, | ||
device_serial_number, | ||
serial_number, | ||
coordinator, | ||
): | ||
super().__init__( | ||
description=description, | ||
name=name, | ||
device_name=device_name, | ||
device_serial_number=device_serial_number, | ||
serial_number=serial_number, | ||
coordinator=coordinator | ||
) | ||
|
||
@property | ||
def native_value(self): | ||
"""Return the state of the sensor.""" | ||
if ( | ||
self.coordinator.data.get("batteries_power") is not None | ||
): | ||
power = self.coordinator.data.get("batteries_power").get( | ||
self._serial_number | ||
).get("real_power_mw") | ||
return (power / -1000) | ||
|
||
return None | ||
@property | ||
def unique_id(self): | ||
"""Return the unique id of the sensor.""" | ||
if self._serial_number: | ||
return f"{self._serial_number}_power" | ||
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. This creates a unique_id like
If you want to keep the option for future migration to the HA Core integration as open as possible, consider using
As that's the unique_id created by the core one. |
||
if self._device_serial_number: | ||
return f"{self._device_serial_number}_{self.entity_description.key}" | ||
|
||
class TotalBatteryCapacityEntity(CoordinatedEnvoyEntity): | ||
def __init__( | ||
self, | ||
|
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 replaces a value reported by the Envoy with a calculated value. This integration is always reporting Envoy values as they are. So best add a new entity like calculated_consumption and give it the value of the calculation.
Also, with the construct !=0 the calculation will not be done when battery is not charging or discharging (value=0), and if so, in current construct the entity will then use the value from the CT again. Again, best use a new entity for this