home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.47k stars 28.66k forks source link

Unable to add a new Gardena Water Computer #117550

Open alistair23 opened 1 month ago

alistair23 commented 1 month ago

The problem

When attempting to add a new computer I keep getting this error

2024-05-16 14:58:32.604 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Gardena 
Water Computer for gardena_bluetooth
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 575, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/gardena_bluetooth/__init__.py", line 55, in async
_setup_entry
    sw_version = await client.read_char(DeviceInformation.firmware_version, None)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gardena_bluetooth/client.py", line 180, in read_char
    return char.decode(await self.read_char_raw(char.uuid))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gardena_bluetooth/parse.py", line 82, in decode
    return data.decode("ASCII")
           ^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 3: ordinal not in range(128)

What version of Home Assistant Core has the issue?

core-2024.5.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

gardena_bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/gardena_bluetooth

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @elupus, mind taking a look at this issue as it has been labeled with an integration (gardena_bluetooth) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `gardena_bluetooth` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign gardena_bluetooth` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


gardena_bluetooth documentation gardena_bluetooth source (message by IssueLinks)

elupus commented 1 month ago

Can you check with the official client what firmware that report (full string including any special characters)

alistair23 commented 1 month ago

This is what I get from manually running your Python scripts

Service: 0000180a-0000-1000-8000-00805f9b34fb (Handle: 16): Gardena DeviceInformation
 -  00002a26-0000-1000-8000-00805f9b34fb (Handle: 21): Gardena DeviceInformation Firmware Version
 -  ['read']
 -  Data: bytearray(b'1.7.23.29')
 -  00002a29-0000-1000-8000-00805f9b34fb (Handle: 19): Gardena DeviceInformation Manufacturer Name
 -  ['read']
 -  Data: bytearray(b'Husqvarna AB')
 -  00002a24-0000-1000-8000-00805f9b34fb (Handle: 17): Gardena DeviceInformation Model Number
 -  ['read']
 -  Data: bytearray(b'Model Number TBD')

If I remove the default argument to read_char() I get this error

gardena_bluetooth.exceptions.CharacteristicNotFound: Unable to find characteristic CharacteristicString(u
uid='00002a26-0000-1000-8000-00805f9b34fb', name='Firmware Version')

So for some reason it can't read the characteristic and by default it returns None, which then can't be decoded

elupus commented 1 month ago

I cant make what you wrote above make sense. First it seems like it did read the firmware version, then you then say didnt.

Are you sure both those attempts are from the same device? Also its not showing same error as it did in HA, so further indicate a different device.

elupus commented 1 month ago

Ps. None would not be equal to the hex char 0xe4 mentioned in your initial log.

alistair23 commented 1 month ago

Are you sure both those attempts are from the same device? Also its not showing same error as it did in HA, so further indicate a different device.

It's possible the first error is from a Husqvarna mower. The integration doesn't print addresses or allow specifying one so it's hard to be sure

elupus commented 1 month ago

It should not list the mower, so aught to have been a watering computer.

alistair23 commented 1 month ago

This diff fixes the issue

diff --git a/homeassistant/components/gardena_bluetooth/config_flow.py b/homeassistant/components/gardena_bluetooth/config_flow.py
index c7631b62f4..cd6070bc41 100644
--- a/homeassistant/components/gardena_bluetooth/config_flow.py
+++ b/homeassistant/components/gardena_bluetooth/config_flow.py
@@ -76,8 +76,6 @@ class GardenaBluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
             raise AbortFlow(
                 "cannot_connect", description_placeholders={"error": str(exception)}
             ) from exception
-        finally:
-            await client.disconnect()

         return {CONF_ADDRESS: self.address}

It looks like the disconnect and connect are too quick for ESPHome, so the setup fails. Running firmware 1.7.23.29 on a Gardena device

elupus commented 1 month ago

That is the old change of never disconnecting which is not acceptable.

What espproxy version are you using?

elupus commented 1 month ago

For the original issue here. A change in the library to ignore unknown chars on decode would be acceptable.

elupus commented 1 month ago

The fast reconnect we could solve with some explicit delay after disconnect.

alistair23 commented 1 month ago

That is the old change of never disconnecting which is not acceptable.

It's just not disconnecting during initial setup. I really never understood why you think it's not a good idea

What espproxy version are you using?

2024.5.0

elupus commented 1 month ago

Because the client object is not shared. It will construct a new object when the entry is setup. So now there are two clients active, one that will potentially disconnect at some random time in the future.

Did you try the suggested esp idf upgrade that bdraco suggested in the other thread.

alistair23 commented 1 month ago

ESPHome 2024.5.0 uses esp idf 4.4.7, it's the latest and greatest

alistair23 commented 1 week ago

With https://github.com/home-assistant/core/pull/119010 I now see this

2024-06-10 14:48:59.997 DEBUG (MainThread) [gardena_bluetooth.client] Connected to F0:5E:CD:2D:C2:F9
2024-06-10 14:49:00.177 DEBUG (MainThread) [gardena_bluetooth.client] Characteristics: {'00002a27-0000-10
00-8000-00805f9b34fb', '00002a24-0000-1000-8000-00805f9b34fb', '00002a50-0000-1000-8000-00805f9b34fb', '0
0002aa6-0000-1000-8000-00805f9b34fb', '00002a05-0000-1000-8000-00805f9b34fb', '00002a2a-0000-1000-8000-00
805f9b34fb', '00002a01-0000-1000-8000-00805f9b34fb', '00002a29-0000-1000-8000-00805f9b34fb', '00002a26-00
00-1000-8000-00805f9b34fb', '00002a25-0000-1000-8000-00805f9b34fb', 'f000ffc1-0451-4000-b000-000000000000
', 'f000ffc5-0451-4000-b000-000000000000', '00002a23-0000-1000-8000-00805f9b34fb', 'f000ffc2-0451-4000-b0
00-000000000000', '00002ac9-0000-1000-8000-00805f9b34fb', '00002a28-0000-1000-8000-00805f9b34fb', '00002a
04-0000-1000-8000-00805f9b34fb', '00002a00-0000-1000-8000-00805f9b34fb'}
2024-06-10 14:49:00.182 DEBUG (MainThread) [gardena_bluetooth.client] No timestamp defined for device
2024-06-10 14:49:00.235 DEBUG (MainThread) [custom_components.gardena_bluetooth] Finished fetching Garden
a Bluetooth Data Update Coordinator data in 0.000 seconds (success: True)

No errors, but I get No devices or entities in HA and am unable to control or see any activity from the device

elupus commented 1 week ago

Interesting! The characteristics listed indicate the device is in firmware update mode. Either the firmware update wasn't finished in the official client or something has triggered it to enter firmware update mode.

alistair23 commented 1 week ago

Weird. The device works fine with the official client though. I can start and stop the water and everything

alistair23 commented 1 week ago

I reset the device and same issue

alistair23 commented 1 day ago

This the ESPHome log

[09:12:06][I][bluetooth_proxy:278]: [0] [F0:5E:CD:2D:C2:F9] Connecting v3 with cache
[09:12:06][D][esp32_ble_tracker:215]: Pausing scan to make connection...
[09:12:06][I][esp32_ble_client:067]: [0] [F0:5E:CD:2D:C2:F9] 0x00 Attempting BLE connection
[09:12:06][D][esp32_ble_client:110]: [0] [F0:5E:CD:2D:C2:F9] ESP_GATTC_CONNECT_EVT
[09:12:06][D][esp32_ble_client:110]: [0] [F0:5E:CD:2D:C2:F9] ESP_GATTC_OPEN_EVT
[09:12:06][I][esp32_ble_client:154]: [0] [F0:5E:CD:2D:C2:F9] Connected
[09:12:06][D][esp32_ble_tracker:266]: Starting scan...
[09:12:09][D][esp32_ble_client:306]: [0] [F0:5E:CD:2D:C2:F9] Event 46
[09:12:09][D][esp32_ble_client:188]: [0] [F0:5E:CD:2D:C2:F9] cfg_mtu status 0, mtu 247
[09:12:09][D][esp32_ble_client:110]: [0] [F0:5E:CD:2D:C2:F9] ESP_GATTC_READ_CHAR_EVT
[09:12:09][D][esp32_ble_client:110]: [0] [F0:5E:CD:2D:C2:F9] ESP_GATTC_READ_CHAR_EVT
[09:12:09][D][esp32_ble_client:110]: [0] [F0:5E:CD:2D:C2:F9] ESP_GATTC_READ_CHAR_EVT
alistair23 commented 1 day ago

And manually running it from a PC

python -m gardena_bluetooth connect F0:5E:CD:2D:C2:F9
Connecting to: F0:5E:CD:2D:C2:F9
Service: 98bd0010-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 23): Gardena Sensor
 -  98bd0016-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 36): Gardena Sensor Measurement Timestamp
 -  ['read', 'notify']
 -  Data: 1970-01-01 10:00:00
 -  98bd0012-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 27): Gardena Sensor Connected State
 -  ['read', 'notify']
 -  Data: False
 -  98bd0017-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 39): Gardena Sensor Force Measurement
 -  ['read', 'write', 'notify']
 -  Data: 0
 -  98bd0014-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 32): Gardena Sensor Threshold
 -  ['read', 'write']
 -  Data: 80
 -  98bd0011-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 24): Gardena Sensor Value
 -  ['read', 'notify']
 -  Data: 0
 -  98bd0015-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 34): Gardena Sensor Battery Level
 -  ['read']
 -  Data: 0
 -  98bd0013-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 30): Gardena Sensor Type
 -  ['read']
 -  Data: 
Service: 00001801-0000-1000-8000-00805f9b34fb (Handle: 12): Generic Attribute Profile
 -  00002a05-0000-1000-8000-00805f9b34fb (Handle: 13): Service Changed
 -  ['indicate']
Service: 98bd0c30-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 95): Unknown
 -  98bd0c36-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 106): Unknown
 -  ['read', 'write']
 -  98bd0c33-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 100): Unknown
 -  ['read', 'write']
 -  98bd0c34-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 102): Unknown
 -  ['read', 'write']
 -  98bd0c31-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 96): Unknown
 -  ['read', 'write']
 -  98bd0c32-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 98): Unknown
 -  ['read', 'write']
 -  98bd0c35-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 104): Unknown
 -  ['read', 'write']
Service: 0000180a-0000-1000-8000-00805f9b34fb (Handle: 16): Gardena DeviceInformation
 -  00002a24-0000-1000-8000-00805f9b34fb (Handle: 17): Gardena DeviceInformation Model Number
 -  ['read']
 -  Data: Model Number TBD
 -  00002a26-0000-1000-8000-00805f9b34fb (Handle: 21): Gardena DeviceInformation Firmware Version
 -  ['read']
 -  Data: 1.7.23.29
 -  00002a29-0000-1000-8000-00805f9b34fb (Handle: 19): Gardena DeviceInformation Manufacturer Name
 -  ['read']
 -  Data: Husqvarna AB
Service: 98bd0c10-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 69): Unknown
 -  98bd0c13-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 74): Unknown
 -  ['read', 'write']
 -  98bd0c11-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 70): Unknown
 -  ['read', 'write']
 -  98bd0c12-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 72): Unknown
 -  ['read', 'write']
 -  98bd0c15-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 78): Unknown
 -  ['read', 'write']
 -  98bd0c16-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 80): Unknown
 -  ['read', 'write']
 -  98bd0c14-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 76): Unknown
 -  ['read', 'write']
Service: 98bdeeee-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 53): Gardena ErrorHistory
 -  98bdeeef-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 54): Gardena ErrorHistory Error Id
 -  ['read']
 -  Data: bytearray(b'\x01\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04')
 -  98bdeef0-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 56): Gardena ErrorHistory Error Count
 -  ['read', 'notify']
 -  Data: 13
Service: f000ffd0-0451-4000-b000-000000000000 (Handle: 121): Gardena Oad
 -  f000ffd1-0451-4000-b000-000000000000 (Handle: 122): Gardena Oad Enable Oad
 -  ['write-without-response', 'write']
Service: 98bd0f10-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 108): Gardena Valve
 -  98bd0f14-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 117): Gardena Valve Manual Watering Time
 -  ['read', 'write']
 -  Data: 1800
 -  98bd0f12-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 112): Gardena Valve Connected State
 -  ['read', 'notify']
 -  Data: True
 -  98bd0f11-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 109): Gardena Valve State
 -  ['read', 'notify']
 -  Data: False
 -  98bd0f13-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 115): Gardena Valve Remaining Open Time
 -  ['read', 'write']
 -  Data: 0
 -  98bd0f15-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 119): Gardena Valve Activation Reason
 -  ['read']
 -  Data: 0
Service: 98bd0d10-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 59): Gardena WateringHistory
 -  98bd0d11-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 60): Gardena WateringHistory Timestamp Array
 -  ['read']
 -  Data: [datetime.datetime(2024, 6, 15, 0, 0), datetime.datetime(2024, 6, 15, 0, 30, 2), datetime.datetime(2024, 6, 15, 1, 17, 22), datetime.datetime(2024, 6, 15, 1, 53), datetime.datetime(2024, 6, 15, 1, 53, 5), datetime.datetime(2024, 6, 15, 17, 38, 52), datetime.datetime(2024, 6, 15, 18, 13, 54), datetime.datetime(2024, 6, 15, 19, 28, 20), datetime.datetime(2024, 6, 15, 20, 3, 17), datetime.datetime(2024, 6, 15, 20, 33, 19), datetime.datetime(2024, 6, 15, 21, 18, 7)]
 -  98bd0d13-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 65): Gardena WateringHistory Skip Reason
 -  ['read']
 -  Data: bytearray(b'"\x00\x00\x02\x02\x00\x00\x00\x02\x00\x00')
 -  98bd0d12-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 62): Gardena WateringHistory Timestamp Count
 -  ['read', 'notify']
 -  Data: 11
 -  98bd0d14-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 67): Gardena WateringHistory Watering Duration
 -  ['read']
 -  Data: [0, 1800, 1800, 62, 4, 1800, 1800, 1800, 6, 1801, 1801]
Service: 98bd180f-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 42): Gardena Battery
 -  98bd2a19-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 43): Gardena Battery Battery Level
 -  ['read', 'notify']
 -  Data: 33
Service: 98bd0b10-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 46): Gardena DeviceConfiguration
 -  98bd0b13-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 51): Gardena DeviceConfiguration Unix Timestamp
 -  ['read', 'write']
 -  Data: 2024-06-17 18:59:03
 -  98bd0b12-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 49): Gardena DeviceConfiguration Seasonal Adjust
 -  ['read', 'write']
 -  Data: 100
 -  98bd0b11-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 47): Gardena DeviceConfiguration Rain Pause
 -  ['read', 'write']
 -  Data: 0
Service: 98bd0c20-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 82): Unknown
 -  98bd0c24-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 89): Unknown
 -  ['read', 'write']
 -  98bd0c23-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 87): Unknown
 -  ['read', 'write']
 -  98bd0c25-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 91): Unknown
 -  ['read', 'write']
 -  98bd0c21-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 83): Unknown
 -  ['read', 'write']
 -  98bd0c22-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 85): Unknown
 -  ['read', 'write']
 -  98bd0c26-0b0e-421a-84e5-ddbf75dc6de4 (Handle: 93): Unknown
 -  ['read', 'write']