TionAPI / HA-tion

Home assistant integration for Tion breezers
Apache License 2.0
72 stars 5 forks source link

HA не может получить статус TION S3 #29

Closed shan197513 closed 3 years ago

shan197513 commented 3 years ago

tion Посмотрите модуль пытается писать Writing 3d0100000000000000000000000000000000005a to 6e400002-b5a3-f393-e0a9-e50e24dcca9e хотя у меня другой UUID (6e400001-b5a3-f393-e0a9-e50e24dcca9e). Это так и должно быть?

shan197513 commented 3 years ago

Попытался еще раз и тоже самое. 2020-12-16 15:43:49 DEBUG (MainThread) [custom_components.tion.config_flow] Real pairing step 2020-12-16 15:43:49 DEBUG (MainThread) [custom_components.tion.config_flow] {'model': 'S3', 'name': 'Tion Breezer', 'mac': 'FC:96:CA:58:1D:01', 'keep_alive': 60, 'away_temp': 15, 'pair': True} 2020-12-16 15:43:49 DEBUG (MainThread) [tion_btle.tion] Pairing 2020-12-16 15:43:50 DEBUG (MainThread) [tion_btle.tion] Enabling notification 2020-12-16 15:43:50 DEBUG (MainThread) [tion_btle.tion] Delegation enabled 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] First read done 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] enable_notification is done 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Connected. BT pairing ... 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Got response while sending pair command: {'rsp': ['mgmt'], 'code': ['mgmterr'], 'estat': [19], 'emsg': ['Already Paired']} 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Already Paired 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Device-specific pairing ... 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.s3] Sending pair command 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Doing _try_write. Attempt 1/3 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Writing 3d0501000000000000000000000000000000005a to 6e400002-b5a3-f393-e0a9-e50e24dcca9e 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.s3] Done! 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] Device pair is done 2020-12-16 15:43:51 DEBUG (MainThread) [tion_btle.tion] disconnected 2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] Enabling notification 2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] Delegation enabled 2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] First read done 2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] enable_notification is done 2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] Doing _try_write. Attempt 1/3 2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] Writing 3d0100000000000000000000000000000000005a to 6e400002-b5a3-f393-e0a9-e50e24dcca9e 2020-12-16 15:44:05 DEBUG (MainThread) [tion_btle.s3] Waiting too long for data 2020-12-16 15:44:05 ERROR (MainThread) [custom_components.tion.config_flow] Cannot pair and get data. Data is {'model': 'S3', 'name': 'Tion Breezer', 'mac': 'FC:96:CA:58:1D:01', 'keep_alive': 60, 'away_temp': 15, 'pair': True}, result is {}; TionException: ('s3 _get_data_from_breezer', 'Could not get breezer state')

IATkachenko commented 3 years ago

Вам нужна немного другая команда для получения информации о доступных характеристиках:

[bluetooth]# connect FC:96:CA:58:1D:01
[Tion Breezer 3S]# menu gatt
[Tion Breezer 3S]# list-attributes
Primary Service
        /org/bluez/hci0/dev_FC_96_CA_58_1D_01/service0009
        6e400001-b5a3-f393-e0a9-e50e24dcca9e
        Nordic UART Service
Characteristic
        /org/bluez/hci0/dev_FC_96_CA_58_1D_01/service0009/char000d
        6e400002-b5a3-f393-e0a9-e50e24dcca9e
        Nordic UART TX
Characteristic
        /org/bluez/hci0/dev_FC_96_CA_58_1D_01/service0009/char000a
        6e400003-b5a3-f393-e0a9-e50e24dcca9e
        Nordic UART RX
Descriptor
        /org/bluez/hci0/dev_FC_96_CA_58_1D_01/service0009/char000a/desc000c
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
Primary Service
        /org/bluez/hci0/dev_FC_96_CA_58_1D_01/service0008
        00001801-0000-1000-8000-00805f9b34fb
        Generic Attribute Profile
[Tion Breezer 3S]# back
[Tion Breezer 3S]# disconnect
[bluetooth]#

Подскажите, пожалуйста, какая у вас версия прошивки? Сейчас актуальна проблема с #23 на прошивке 003C, у меня на 0033 все работает корректно. Но не похоже что это -- ваш случай: после того как вы сделали pair на попытке получения данных вы успешно подключаетесь к бризеру, те pair-стадия все же проходит. Попробуйте теперь добавить бризер в HA без pairing'a: вы должны успешно подключиться к бризеру. А дальше варианты: или опять "Waiting too long for data" или все заработает.

Вот так выглядит описание того что вы увидели: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/bluetooth/services/nus.html те девайс говорит что у него есть Nordic UART Service и дальше мы работаем с соответствующими UUID для отправки/получения данных.

shan197513 commented 3 years ago

Прошивка 0033. После попытки добавить бризер в HA без pairing'a опять "Waiting too long for data".

IATkachenko commented 3 years ago

Но при этом никаких ошибок связанных с connect? Если ошибок connect нет, то pairing у вас прошел правильно, но есть проблема с получением данных. Запустите, пожалуйста, вот такой скрипт (чтобы упростить отладку и не гонять HA) и пришлите его вывод.

import logging
from tion_btle.s3 import S3

logging.basicConfig(level=logging.DEBUG)
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel("DEBUG")

mac = "FC:96:CA:58:1D:01"
device = S3(mac)
result = device.get()

_LOGGER.debug("Result is %s " % result)

_LOGGER.info("Initial state: device is %s, sound is %s, heater is %s, fan_speed is %d, target_temp is %d",
              device.state,
              device.sound,
              device.heater,
              device.fan_speed,
              device.target_temp
              )

И, на всякий случай,

pip3 list | grep tion-btle 

говорит что версия 1.1.1?

На своем бризере я получаю вашу ошибку, если не делается first read, но у вас он проходит без ошибок

2020-12-16 15:43:55 DEBUG (MainThread) [tion_btle.tion] First read done
IATkachenko commented 3 years ago

Проблема аналогична https://github.com/TionAPI/tion_python/issues/17

shan197513 commented 3 years ago

Хорошо, но как запустить скрипт в docker? (я не знаю), как Вы пишите не гоняя НА.

IATkachenko commented 3 years ago

Как мы выяснили в issue модуля (ссылка выше) на версии 1.1.1 запуск ничего не даст. Проверить нужно версию tion-btle==1.1.2a1. Попасть внутрь контейнера можно, например так (при запущенном контейнере): docker exec -it имя_контейнера bash А дальше, например:

pip3 install tion-btle==1.1.2a1
vi script.py
python3 script.py
pip3 install tion-btle==1.1.1

с pip возможны вариации.

shan197513 commented 3 years ago

Получилось

bash-5.0# python3 script.py DEBUG:tion_btle.tion:Enabling notification DEBUG:tion_btle.tion:Notify handler is 11 DEBUG:tion_btle.tion:Will write b'\x01\x00' to 12 handle DEBUG:tion_btle.tion:Result is {'rsp': ['wr']} DEBUG:tion_btle.tion:Delegation enabled DEBUG:tion_btle.tion:First read done. Data is a6 DEBUG:tion_btle.tion:enable_notification is done DEBUG:tion_btle.tion:Doing _try_write. Attempt 1/3 DEBUG:tion_btle.tion:Writing 3d0100000000000000000000000000000000005a to 6e400002-b5a3-f393-e0a9-e50e24dcca9e DEBUG:tion_btle.tion:Got data in 11 response b310221e000111110934010a240000310033005a DEBUG:tion_btle.s3:Data is b310221e000111110934010a240000310033005a DEBUG:main:Result is {'state': 'off', 'heater': 'off', 'heating': 'off', 'sound': 'off', 'mode': 'outside', 'out_temp': 17, 'in_temp': 9, 'heater_temp': 30, 'fan_speed': 2, 'filter_remain': 308, 'time': '10:36', 'request_error_code': 0, 'model': 'S3', 'code': 200, 'timer': 'off', 'productivity': 0, 'fw_version': '0033'} INFO:main:Initial state: device is off, sound is off, heater is off, fan_speed is 2, target_temp is 30

shan197513 commented 3 years ago

Также успешно добавилось в HA (без pair)

IATkachenko commented 3 years ago

Pair у вас прошел чуть раньше. Спасибо за тест. В ближайшее время сделаю релиз.

IATkachenko commented 3 years ago

Fixed in v1.4.3