t3chguy / pinecil_ble

Integrates Pinecil v2 soldering iron into HomeAssistant via BLE
MIT License
17 stars 1 forks source link

Error when configuring this integration (AttributeError: 'PinecilWrapper' object has no attribute 'result') #8

Closed ColColonCleaner closed 5 months ago

ColColonCleaner commented 5 months ago

Hello there! Thank you for making this so easy to integrate into HA! Unfortunately I'm running into a problem when trying to add my pinecil. I looked at your PinecilWrapper class and it seems to have a 'result' attribute, so I'm not sure why it's complaining about that.

ERROR (MainThread) [custom_components.pinecil_ble] Unexpected error fetching pinecil_ble data Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _async_update_data return await self.update_method() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/pinecil_ble/init.py", line 34, in _async_update await pinecil.update() File "/config/custom_components/pinecil_ble/models.py", line 57, in update return self.result ^^^^^^^^^^^ AttributeError: 'PinecilWrapper' object has no attribute 'result'

ColColonCleaner commented 5 months ago

I've confirmed that the pinecil is connected and the data is flowing, but the final result being sent back to HA is failing.

ColColonCleaner commented 5 months ago

Interesting. Line 57 would only be executed if it doesn't have a device connection, but I've confirmed that entering an incorrect mac address results in a connection error instead of the error about no result attribute. So it's definitely connected, but it seems _async_update_ble is not getting called to set the device info.

ColColonCleaner commented 5 months ago

It's a capitalization issue. The integration does the initial check for existence by converting the mac address to uppercase, but it still keeps reference with the original lowercase mac address. Converting the input mac address to uppercase immediately and using that value everywhere should fix this.

The pinecil is working now via HA. Fantastic!

Unfortunately it doesn't look like it works through BLE proxies, and my workshop is only accessible from HA via those proxies since it's too far away otherwise :( Have several dozen proxies (shelly plus relays/switches), and other BLE devices like switchbot temperature sensors operate through them fine but this one seems to have issues with that.

t3chguy commented 5 months ago

Interesting observation re casing, I will look into that. Re proxies, my HA only has BT access via Shelly & ESPHome proxies and manages to connect fine so not sure why that does not work for you

ColColonCleaner commented 5 months ago

It's this line specifically. The address variable isn't changed to uppercase itself, the value is only changed to uppercase in the call to async_ble_device_from_address: https://github.com/t3chguy/pinecil_ble/blob/e4fdea35d6ea50f2cd43ec9d8b2967bfa7576c54/custom_components/pinecil_ble/__init__.py#L28 This means it's still lower case when trying to match the device later on, so the device and the callback can never match: https://github.com/t3chguy/pinecil_ble/blob/e4fdea35d6ea50f2cd43ec9d8b2967bfa7576c54/custom_components/pinecil_ble/__init__.py#L58

For the proxies, not sure why that's not working for me. I may try re-adding it far away from the host machine after cold rebooting it, so it's only visible via the proxies. Hopefully that works.

ColColonCleaner commented 5 months ago

Didn't end up getting the proxies to work with the pinecil so took a different approach. I was already using esphome to control a fume extractor and blast gates in my workshop so I used the following code to add a BLE connection between the pinecil and that esp32. The fume extraction can now run automatically when soldering! https://github.com/TomW1605/esphome_pinecilv2_ble/blob/main/esphome_pinecilv2_ble.yaml