fix device type info
This commit is contained in:
1 parent
206099ab64
commit
12a59346e9
2 files changed
+12
-2
No files matched your search
@@ -53,6 +53,6 @@ def build_device(address: str, name: str):
|
|||||||
|
|
||||||
def get_type_by_bt_name(bt_name: str):
|
def get_type_by_bt_name(bt_name: str):
|
||||||
match = DEVICE_NAME_RE.match(bt_name)
|
match = DEVICE_NAME_RE.match(bt_name)
|
||||||
if match is None or len(match) < 2:
|
if match is None:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
return match[1]
|
return match[1]
|
||||||
@@ -14,7 +14,7 @@ from homeassistant.components.bluetooth import (
|
|||||||
BluetoothServiceInfoBleak,
|
BluetoothServiceInfoBleak,
|
||||||
async_discovered_service_info,
|
async_discovered_service_info,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_ADDRESS, CONF_NAME
|
from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_TYPE
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
|
|
||||||
@@ -48,11 +48,20 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
await self.async_set_unique_id(discovery_info.address)
|
await self.async_set_unique_id(discovery_info.address)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
|
if isinstance(discovery_info.name, str):
|
||||||
|
name = re.sub("[^A-Z0-9]+", "", discovery_info.name)
|
||||||
|
discovery_info.manufacturer_data = {
|
||||||
|
CONF_TYPE: get_type_by_bt_name(name)
|
||||||
|
}
|
||||||
|
|
||||||
# Get device type if needed
|
# Get device type if needed
|
||||||
if isinstance(discovery_info.name, str) and discovery_info.name.startswith("PBOX"):
|
if isinstance(discovery_info.name, str) and discovery_info.name.startswith("PBOX"):
|
||||||
bleak_device = BleakClient(discovery_info.device)
|
bleak_device = BleakClient(discovery_info.device)
|
||||||
device_type = await recognize_device(bleak_device, self.hass.loop.create_future)
|
device_type = await recognize_device(bleak_device, self.hass.loop.create_future)
|
||||||
_LOGGER.info("Device identified as %s", device_type)
|
_LOGGER.info("Device identified as %s", device_type)
|
||||||
|
discovery_info.manufacturer_data = {
|
||||||
|
CONF_TYPE: device_type.strip(),
|
||||||
|
}
|
||||||
discovery_info.name = discovery_info.name.replace("PBOX", device_type.strip())
|
discovery_info.name = discovery_info.name.replace("PBOX", device_type.strip())
|
||||||
|
|
||||||
self._discovery_info = discovery_info
|
self._discovery_info = discovery_info
|
||||||
@@ -76,6 +85,7 @@ class BluettiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
data={
|
data={
|
||||||
CONF_ADDRESS: discovery_info.address,
|
CONF_ADDRESS: discovery_info.address,
|
||||||
CONF_NAME: name,
|
CONF_NAME: name,
|
||||||
|
CONF_TYPE: discovery_info.manufacturer_data.get(CONF_TYPE, "Unknown"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user