Better mesh filtering. Also multiple outputs?

This commit is contained in:
Thomas Lovén 2022-10-17 21:31:13 +02:00
parent a7ecb054c1
commit d4254be81b
4 changed files with 15 additions and 16 deletions

View File

@ -45,7 +45,7 @@ class PlejdLight(LightEntity, CoordinatorEntity):
@property @property
def device_info(self): def device_info(self):
return { return {
"identifiers": {(DOMAIN, self.device.BLE_address)}, "identifiers": {(DOMAIN, f"{self.device.BLE_address}:{self.device.address}")},
"name": self.device.name, "name": self.device.name,
"manufacturer": "Plejd", "manufacturer": "Plejd",
"model": {self.device.model}, "model": {self.device.model},
@ -64,7 +64,7 @@ class PlejdLight(LightEntity, CoordinatorEntity):
@property @property
def unique_id(self): def unique_id(self):
return self.device.BLE_address return f"{self.device.BLE_address}:{self.device.address}"
@property @property
def is_on(self): def is_on(self):

View File

@ -22,10 +22,11 @@ class PlejdManager:
def add_mesh_device(self, device): def add_mesh_device(self, device):
_LOGGER.debug("Adding plejd %s", device) _LOGGER.debug("Adding plejd %s", device)
for d in self.devices.values(): # for d in self.devices.values():
if d.BLE_address.upper() == device.address.replace(":","").replace("-","").upper(): # addr = device.address.replace(":","").replace("-","").upper()
# if d.BLE_address.upper() == addr or addr in device.name:
return self.mesh.add_mesh_node(device) return self.mesh.add_mesh_node(device)
_LOGGER.debug("Device was not expected in current mesh") # _LOGGER.debug("Device was not expected in current mesh")
async def close_stale(self, device): async def close_stale(self, device):
_LOGGER.info("Closing stale connections for %s", device) _LOGGER.info("Closing stale connections for %s", device)

View File

@ -68,6 +68,12 @@ class PlejdMesh():
client = await establish_connection(BleakClient, plejd, "plejd", _disconnect) client = await establish_connection(BleakClient, plejd, "plejd", _disconnect)
address = plejd.address address = plejd.address
self._connected = True self._connected = True
self.client = client
_LOGGER.debug("Connected to Plejd mesh")
await asyncio.sleep(2)
if not await self._authenticate():
await self.disconnect()
continue
break break
except (BleakError, asyncio.TimeoutError) as e: except (BleakError, asyncio.TimeoutError) as e:
_LOGGER.warning("Error connecting to Plejd device: %s", str(e)) _LOGGER.warning("Error connecting to Plejd device: %s", str(e))
@ -78,16 +84,8 @@ class PlejdMesh():
_LOGGER.warning("Failed to connect to plejd mesh - %s", self.mesh_nodes) _LOGGER.warning("Failed to connect to plejd mesh - %s", self.mesh_nodes)
return False return False
self.client = client
self.connected_node = binascii.a2b_hex(address.replace(":", "").replace("-", ""))[::-1] self.connected_node = binascii.a2b_hex(address.replace(":", "").replace("-", ""))[::-1]
_LOGGER.debug("Connected to Plejd mesh")
await asyncio.sleep(2)
if not await self._authenticate():
await self.disconnect()
return False
async def _lastdata(_, lastdata): async def _lastdata(_, lastdata):
self.pollonWrite = False self.pollonWrite = False
data = encrypt_decrypt(self.crypto_key, self.connected_node, lastdata) data = encrypt_decrypt(self.crypto_key, self.connected_node, lastdata)

View File

@ -45,7 +45,7 @@ class PlejdSwitch(SwitchEntity, CoordinatorEntity):
@property @property
def device_info(self): def device_info(self):
return { return {
"identifiers": {(DOMAIN, self.device.BLE_address)}, "identifiers": {(DOMAIN, f"{self.device.BLE_address}:{self.device.address}")},
"name": self.device.name, "name": self.device.name,
"manufacturer": "Plejd", "manufacturer": "Plejd",
"model": self.device.model, "model": self.device.model,
@ -64,7 +64,7 @@ class PlejdSwitch(SwitchEntity, CoordinatorEntity):
@property @property
def unique_id(self): def unique_id(self):
return self.device.BLE_address return f"{self.device.BLE_address}:{self.device.address}"
@property @property
def is_on(self): def is_on(self):