ratcashdev / mitemp

Xiaomi MI Temperature and Humidity Sensor with BLE and LCD
MIT License
106 stars 27 forks source link

Data reading float conversion exception #15

Closed lucagiove closed 4 years ago

lucagiove commented 4 years ago

Sensor data collection stops after the following traceback. Probably there is another bug that prevents data to be collected after an exception not sure if in this repository or in the component code, for sure there are many people affected by this problem: https://github.com/home-assistant/home-assistant/issues/24313

I'll try to work on a PR at least for the parsing exception.

Update for sensor.salotto_temperature fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/mitemp_bt/sensor.py", line 156, in update
    data = self.poller.parameter_value(self.parameter)
  File "/usr/local/lib/python3.7/site-packages/mitemp_bt/mitemp_bt_poller.py", line 126, in parameter_value
    self.fill_cache()
  File "/usr/local/lib/python3.7/site-packages/mitemp_bt/mitemp_bt_poller.py", line 69, in fill_cache
    self.ble_timeout)  # pylint: disable=no-member
  File "/usr/local/lib/python3.7/site-packages/btlewrap/bluepy.py", line 27, in _func_wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/btlewrap/bluepy.py", line 93, in wait_for_notification
    return self._peripheral.waitForNotifications(notification_timeout)
  File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 560, in waitForNotifications
    resp = self._getResp(['ntfy','ind'], timeout)
  File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 416, in _getResp
    self.delegate.handleNotification(hnd, data)
  File "/usr/local/lib/python3.7/site-packages/mitemp_bt/mitemp_bt_poller.py", line 198, in handleNotification
    self._check_data()
  File "/usr/local/lib/python3.7/site-packages/mitemp_bt/mitemp_bt_poller.py", line 145, in _check_data
    parsed = self._parse_data()
  File "/usr/local/lib/python3.7/site-packages/mitemp_bt/mitemp_bt_poller.py", line 181, in _parse_data
    res[MI_HUMIDITY] = float(dataparts[1])
ValueError: could not convert string to float: '53.0\x02'
lucagiove commented 4 years ago

The fix works for the exception, I don't have the float error anymore but the polling crashed anyway with this error: Polling error [Errno 32] Broken pipe

ratcashdev commented 4 years ago

Closing, since #16 is merged. Feel free to file a new issue/pr if you discover the reason behind the Broken Pipe message.

ratcashdev commented 4 years ago

Edit: Crash already reported in #14