Skip to content

Commit

Permalink
fix some errors
Browse files Browse the repository at this point in the history
fix some errors
  • Loading branch information
dave-code-ruiz committed Dec 29, 2022
1 parent b18e6b7 commit f958067
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions custom_components/elkbledom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions custom_components/elkbledom/elkbledom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/elkbledom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit f958067

Please sign in to comment.