Open nikakoy131 opened 1 year ago
Finally, I get this working. Nothing helps me until I ask chatGPT for help )) He says to me -
The code you provided appears to be mostly correct. However, there is one issue that may be causing the KeyError
you encountered.
In the sensor_update_to_bluetooth_data_update
function, when creating the entity_descriptions
dictionary, you're using the description.native_unit_of_measurement
as part of the key to access SENSOR_DESCRIPTIONS
. However, in the SENSOR_DESCRIPTIONS
dictionary, some of the keys have a value of None
for the native unit of measurement.
To fix the issue, you can modify the code as follows:
entity_descriptions = {
PassiveBluetoothEntityKey(
device_key.key, device_key.device_id
): SENSOR_DESCRIPTIONS.get(
(description.device_key.key, description.native_unit_of_measurement),
SENSOR_DESCRIPTIONS.get((description.device_key.key, None))
)
for device_key, description in sensor_update.entity_descriptions.items()
if description.device_key
}
This change allows the code to first try accessing SENSOR_DESCRIPTIONS with both the device key and the native unit of measurement. If that key is not found, it falls back to using the device key and None as the unit of measurement.
This modification should help resolve the KeyError you encountered. Let me know if you need further assistance!
It helped me. Currently, the integration works fine, and shows me missing entity :-) Maybe this helps someone PS: I'm totally not familiar with Python, so I totally don't know what's going on, so use this at your own risk
I had the exact same problem with the SmartSolar controller and this solution fixed it for me. Thanks much!
I see a very similar issue here when activating the "midpoint_voltage" function on the SmartShunt:
Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht
Logger: custom_components.victron_ble
Source: components/bluetooth/passive_update_processor.py:585
Integration: Victron BLE (documentation, issues)
First occurred: 09:41:21 (4343 occurrences)
Last logged: 22:58:36
Unexpected error updating SmartShunt HQ2209R7EDE data: (<VictronSensor.MIDPOINT_VOLTAGE: 'midpoint_voltage'>, <Units.ELECTRIC_POTENTIAL_VOLT: 'V'>)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_processor.py", line 585, in async_handle_update
new_data = self.update_method(update)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/victron_ble/sensor.py", line 151, in sensor_update_to_bluetooth_data_update
entity_descriptions={
^
File "/config/custom_components/victron_ble/sensor.py", line 154, in <dictcomp>
): SENSOR_DESCRIPTIONS[
^^^^^^^^^^^^^^^^^^^^
KeyError: (<VictronSensor.MIDPOINT_VOLTAGE: 'midpoint_voltage'>, <Units.ELECTRIC_POTENTIAL_VOLT: 'V'>)
and the above fix worked for me as well.
... of course this does not add the reading of the midpoint voltage into HA it seems ... but at least the Device is correctly queried and does not fail as a whole.
Found this while troubleshooting why my vehicle based Victron Battery Sense was picked up 100% when I arrive home but my Smart Solar was not auto-connecting and would only get a few data points in after I'd reset the integration manually before hanging again.
After making the code change my External Device Load sensor exits and the device seems to function well.
Thanks for the fix. This is a fantastic integration overall so I'm happy to have it working with both devices.
Has anyone done a PR for this issue? I just ran into it as well.
Version of the custom_component
Latest from HACS Home Assistant 2023.6.3 Supervisor 2023.06.4 Operating System 10.2 Frontend 20230608.0 - latest
Configuration
Describe the bug
All other entities are displayed and work well, only EXTERNAL_DEVICE_LOAD is missing
Debug log