From f9580678b94c585c8245ffc925b4424a1773adc7 Mon Sep 17 00:00:00 2001 From: Dave Code <34915602+dave-code-ruiz@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:56:33 +0100 Subject: [PATCH] fix some errors fix some errors --- custom_components/elkbledom/config_flow.py | 7 ++++--- custom_components/elkbledom/elkbledom.py | 7 +++++-- custom_components/elkbledom/manifest.json | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/elkbledom/config_flow.py b/custom_components/elkbledom/config_flow.py index 2ba9051..97baff8 100644 --- a/custom_components/elkbledom/config_flow.py +++ b/custom_components/elkbledom/config_flow.py @@ -3,7 +3,7 @@ from typing import Any from homeassistant import config_entries -from homeassistant.const import CONF_MAC +from homeassistant.const import CONF_MAC, CONF_MODEL import voluptuous as vol from homeassistant.helpers.device_registry import format_mac from homeassistant.data_entry_flow import FlowResult @@ -14,6 +14,7 @@ ) from bluetooth_sensor_state_data import BluetoothData from home_assistant_bluetooth import BluetoothServiceInfo +from homeassistant.helpers.selector import selector from .const import DOMAIN, CONF_RESET import logging @@ -29,7 +30,7 @@ def __init__(self, discovery_info) -> None: self._discovery = discovery_info def supported(self): - return self._discovery.name.lower().startswith("elk-bledom") or self._discovery.name.lower().startswith("ledble") or self._discovery.name.lower().startswith("melk") + return self._discovery.name.lower().startswith("elk-ble") or self._discovery.name.lower().startswith("ledble") or self._discovery.name.lower().startswith("melk") def address(self): return self._discovery.address @@ -64,7 +65,7 @@ async def async_step_bluetooth( self, discovery_info: BluetoothServiceInfoBleak ) -> FlowResult: """Handle the bluetooth discovery step.""" - LOGGER.debug("Discovered bluetooth devices, step bluetooth, : %s", discovery_info) + LOGGER.debug("Discovered bluetooth devices, step bluetooth, : %s , %s", discovery_info.address, discovery_info.name) await self.async_set_unique_id(discovery_info.address) self._abort_if_unique_id_configured() device = DeviceData(discovery_info) diff --git a/custom_components/elkbledom/elkbledom.py b/custom_components/elkbledom/elkbledom.py index 4834756..5f3b67d 100644 --- a/custom_components/elkbledom/elkbledom.py +++ b/custom_components/elkbledom/elkbledom.py @@ -60,7 +60,7 @@ # [be:59:7a:00:08:d5][LE]> # CHANGES ARRAYS TO DICT OR MODELDB OBJECT WITH ALL MODEL INFORMATION -NAME_ARRAY = ["ELK-BLEDOM", "LEDBLE", "MELK"] +NAME_ARRAY = ["ELK-BLE", "LEDBLE", "MELK"] WRITE_CHARACTERISTIC_UUIDS = ["0000fff3-0000-1000-8000-00805f9b34fb", "0000ffe1-0000-1000-8000-00805f9b34fb", "0000fff3-0000-1000-8000-00805f9b34fb"] READ_CHARACTERISTIC_UUIDS = ["0000fff4-0000-1000-8000-00805f9b34fb", "0000ffe2-0000-1000-8000-00805f9b34fb", "0000fff4-0000-1000-8000-00805f9b34fb"] TURN_ON_CMD = [[0x7e, 0x00, 0x04, 0xf0, 0x00, 0x01, 0xff, 0x00, 0xef],[0x7e, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0xef], bytearray([0x7e, 0x07, 0x83])] @@ -115,6 +115,8 @@ def __init__(self, address, reset: bool, hass) -> None: self._hass = hass self._device: BLEDevice | None = None self._device = bluetooth.async_ble_device_from_address(self._hass, address, connectable=True) + if not self._device: + raise ConfigEntryNotReady(f"Couldn't find a nearby device with address: {address}") self._connect_lock: asyncio.Lock = asyncio.Lock() self._client: BleakClientWithServiceCache | None = None self._disconnect_timer: asyncio.TimerHandle | None = None @@ -131,6 +133,7 @@ def __init__(self, address, reset: bool, hass) -> None: self._turn_on_cmd = None self._turn_off_cmd = None self._model = self._detect_model() + LOGGER.debug('Model information for device %s : ModelNo %s, Turn on cmd %s, Turn off cmd %s', self._device.name, self._model, self._turn_on_cmd, self._turn_off_cmd) def _detect_model(self): x = 0 @@ -188,7 +191,7 @@ def effect(self): @retry_bluetooth_connection_error async def set_white(self, intensity: int): - await self._write([0x7e, 0x00, 0x01, intensity, 0x00, 0x00, 0x00, 0x00, 0xef]) + await self._write([0x7e, 0x00, 0x01, int(intensity*100/255), 0x00, 0x00, 0x00, 0x00, 0xef]) self._brightness = intensity @retry_bluetooth_connection_error diff --git a/custom_components/elkbledom/manifest.json b/custom_components/elkbledom/manifest.json index 2183d79..7649320 100644 --- a/custom_components/elkbledom/manifest.json +++ b/custom_components/elkbledom/manifest.json @@ -8,10 +8,10 @@ "codeowners": ["@dave-code-ruiz"], "requirements": ["bleak-retry-connector>=1.17.1","bleak>=0.17.0"], "bluetooth": [ - { "local_name": "ELK-BLEDOM*" }, + { "local_name": "ELK-BLE*" }, { "local_name": "MELK*" }, { "local_name": "LEDBLE*" } ], "iot_class": "local_polling", - "version": "0.0.1" + "version": "1.0.0" } \ No newline at end of file