Skip to content

Commit

Permalink
Merge branch 'test' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Zud71 committed Oct 26, 2024
2 parents bb4177f + 6650719 commit b53499a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 41 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

## Поддерживаются
* СГБ-1.8 - работает
* СГБ-3.2
* СГБ-3.2 - работает
* СГБ-4.0 - работает
* СГБ-6.0
* СГБ-1.6
* СГБД-1.8
* СГБД-3.2
* СГБД-3.2 - работает
* СГБД-4.0
* СГБД-6.0
* СГБД-1.6
* СОНИК-G1.6
* СОНИК-G2.5
* СОНИК-G4
* СОНИК-G4 - работает
* СОНИК-G6
* СОНИК-G10
* СГБД-1.8ТК
Expand Down Expand Up @@ -52,14 +52,8 @@

## Установка
### В ручную
1. Скопируйте папку **elehant_meter** в **custom_components** в корне конфигурации Home Assistant
2. В **configuration.yaml** добавьте следующие строки:
Скопируйте папку **elehant_meter** в **custom_components** в корне конфигурации Home Assistant

```yaml
sensor:
- platform: elehant_meter

```
### Через HACS (в работе)
```HACS > Интеграции > 3 точки (правый верхний угол) > Пользовательские репозитории > Вводим: Zud71/elehant_meter, Категория: Интеграция > Добавить > подождать > elehant_meter > Установить```

Expand Down
2 changes: 1 addition & 1 deletion custom_components/elehant_meter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(
coordinator.async_start()
) # only start after all platforms have had a chance to subscribe
)
return True


Expand Down
33 changes: 22 additions & 11 deletions custom_components/elehant_meter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any

from .const import ElehantData
from .const import MANUFACTURER_ID
import voluptuous as vol

from homeassistant import config_entries
Expand Down Expand Up @@ -35,15 +36,21 @@ async def async_step_bluetooth(
"""Handle the Bluetooth discovery step."""

_LOGGER.debug("Обнаружено устройство BT: %s", discovery_info)
_LOGGER.debug("Данные в HEX: %s", discovery_info.manufacturer_data[MANUFACTURER_ID].hex().upper())

await self.async_set_unique_id(discovery_info.address)
self._abort_if_unique_id_configured()
adv = ElehantData(discovery_info.device, discovery_info.advertisement)

if not adv.macdata.signValid:
_LOGGER.debug("Обнаружено неподдерживаемое устройство: %s", discovery_info)
return self.async_abort(reason="not_supported")

self._discovery_info = discovery_info

self._discovered_device = adv
return await self.async_step_bluetooth_confirm()


async def async_step_bluetooth_confirm(
self, user_input: dict[str, Any] | None = None
Expand All @@ -52,20 +59,24 @@ async def async_step_bluetooth_confirm(
assert self._discovered_device is not None
adv = self._discovered_device

title = adv.name
assert title is not None, "Ошибка: Пустой заголовок"
_LOGGER.debug("async_step_bluetooth_confirm: %s", adv)

if user_input is not None:
return self.async_create_entry(title=title, data={})
if adv.macdata.signValid:
title = adv.name
assert title is not None, "Ошибка: Пустой заголовок"

assert title is not None
if user_input is not None:
return self.async_create_entry(title=title, data={})

self._set_confirm_only()
placeholders = {"name": title}
self.context["title_placeholders"] = placeholders
return self.async_show_form(
step_id="bluetooth_confirm", description_placeholders=placeholders
)
self._set_confirm_only()
placeholders = {"name": title}
self.context["title_placeholders"] = placeholders
return self.async_show_form(
step_id="bluetooth_confirm", description_placeholders=placeholders)

else:
_LOGGER.debug("Confirm discovery - не пройден: %s", adv)
return self.async_abort(reason="not_supported")

async def async_step_user(
self, user_input: dict[str, Any] | None = None
Expand Down
46 changes: 28 additions & 18 deletions custom_components/elehant_meter/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bleak.backends.device import BLEDevice
import logging

import json

DOMAIN = "elehant_meter"
_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -97,6 +98,8 @@ class ElehantData:
mtype: int = None
model: int = None
name_model: str = None
frimware: str = None
packetVer: int = None

macdata: MacData = None

Expand All @@ -114,21 +117,20 @@ def __init__(self, device=None, ad_data=None):
self.macdata.signValid = False

raw_bytes = ad_data.manufacturer_data[MANUFACTURER_ID]
check_ff = int.from_bytes(raw_bytes[3:4], byteorder="little")
packetVer = int.from_bytes(raw_bytes[3:4], byteorder="little")

_LOGGER.debug("Версия пакета: %s", packetVer)

if has_manufacurer_data and check_ff == 1:
if has_manufacurer_data and packetVer == 1:
v_num = int.from_bytes(raw_bytes[6:9], byteorder='little')
v_count = int.from_bytes(
raw_bytes[9:13], byteorder='little')
v_temp = int.from_bytes(
raw_bytes[14:16], byteorder="little")
v_battery = int.from_bytes(
raw_bytes[13:14], byteorder="little")

v_mtype = int.from_bytes(
raw_bytes[4:5], byteorder="little")
v_model = int.from_bytes(
raw_bytes[5:6], byteorder="little")
v_count = int.from_bytes(raw_bytes[9:13], byteorder='little')
v_temp = int.from_bytes(raw_bytes[14:16], byteorder="little")
v_battery = int.from_bytes(raw_bytes[13:14], byteorder="little")

v_mtype = int.from_bytes(raw_bytes[4:5], byteorder="little")
v_model = int.from_bytes(raw_bytes[5:6], byteorder="little")

v_fw = int.from_bytes(raw_bytes[16:17], byteorder="little")

if v_mtype == self.macdata.mtype and v_model == self.macdata.model:

Expand Down Expand Up @@ -159,29 +161,33 @@ def __init__(self, device=None, ad_data=None):
self.battery = v_battery
self.mtype = v_mtype
self.model = v_model
self.frimware = v_fw/10
self.rssi = ad_data.rssi

self.macdata.signValid = True


_LOGGER.debug("Имя устройства: %s", self.name)
_LOGGER.debug("MAC: %s", mac)
_LOGGER.debug("ID: %s", self.id_meter)
_LOGGER.debug("Модель: %s", self.name_model)
_LOGGER.debug("Показания: %s", self.meter_reading)
_LOGGER.debug("Темперетара: %s", self.temperature)
_LOGGER.debug("Батарея: %s", self.battery)
_LOGGER.debug("Сигнал: %s", self.rssi)

_LOGGER.debug("Тип мас: %s", self.mtype)
_LOGGER.debug("Модель мас: %s", self.model)
_LOGGER.debug("Сигнал: %s", self.rssi)
_LOGGER.debug("Версия прошивки: %s", self.frimware)

else:
self.macdata.signValid = False
_LOGGER.debug(
"ElehantData init - не пройдена проверка по производителю и контрольному биту MAC %s", mac)
"ElehantData init - не пройдена проверка по производителю или версии пакета MAC %s", mac)
else:
self.macdata.signValid = False
_LOGGER.debug(
"ElehantData init - не пройдена device или ad_data пустые")
"ElehantData init - не пройдена, device или ad_data пустые")


def parse_mac(in_mac) -> MacData:
Expand All @@ -197,8 +203,12 @@ def parse_mac(in_mac) -> MacData:
if (result.mtype == MeterType.GAS and result.model in MeterModel[MeterType.GAS]) or (result.mtype == MeterType.WATER and result.model in MeterModel[MeterType.WATER]):
result.signValid = True
else:
_LOGGER.debug(
"parse_mac Устройство не Елехант только (B0), результат: %s", mac[0:2])
if mac[0:2] == "b1":
_LOGGER.debug(
"parse_mac Устройство Елехант (B1). Данные не расшифрованны, игнорирование, результат: %s", mac[0:2])
else:
_LOGGER.debug(
"parse_mac Устройство не Елехант только (B0 или В1) , результат: %s", mac[0:2])

_LOGGER.debug("parse_mac signValid: %s", result.signValid)
return result
2 changes: 1 addition & 1 deletion custom_components/elehant_meter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/Zud71/elehant_meter/issues",
"requirements": ["bleak"],
"version": "0.1.0"
"version": "0.1.1"
}
1 change: 1 addition & 0 deletions custom_components/elehant_meter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def _sensor_device_info_to_hass(
serial_number=adv.id_meter,
model_id=adv.device.address,
model = adv.name_model,
hw_version=adv.frimware,
manufacturer = "Элехант"
)

Expand Down
Binary file modified images/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b53499a

Please sign in to comment.