Return the real MAC address for LIFX bulbs with newer firmware (#58511)

pull/58977/head
Avi Miller 2021-10-29 03:27:40 +11:00 committed by Paulus Schoutsen
parent 41007c2864
commit 2cae44c98a
1 changed files with 19 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import math
import aiolifx as aiolifx_module import aiolifx as aiolifx_module
import aiolifx_effects as aiolifx_effects_module import aiolifx_effects as aiolifx_effects_module
from awesomeversion import AwesomeVersion
import voluptuous as vol import voluptuous as vol
from homeassistant import util from homeassistant import util
@ -66,6 +67,8 @@ MESSAGE_TIMEOUT = 1.0
MESSAGE_RETRIES = 8 MESSAGE_RETRIES = 8
UNAVAILABLE_GRACE = 90 UNAVAILABLE_GRACE = 90
FIX_MAC_FW = AwesomeVersion("3.70")
SERVICE_LIFX_SET_STATE = "set_state" SERVICE_LIFX_SET_STATE = "set_state"
ATTR_INFRARED = "infrared" ATTR_INFRARED = "infrared"
@ -455,20 +458,34 @@ class LIFXLight(LightEntity):
self.postponed_update = None self.postponed_update = None
self.lock = asyncio.Lock() self.lock = asyncio.Lock()
def get_mac_addr(self):
"""Increment the last byte of the mac address by one for FW>3.70."""
if (
self.bulb.host_firmware_version
and AwesomeVersion(self.bulb.host_firmware_version) >= FIX_MAC_FW
):
octets = [int(octet, 16) for octet in self.bulb.mac_addr.split(":")]
octets[5] = (octets[5] + 1) % 256
return ":".join(f"{octet:02x}" for octet in octets)
return self.bulb.mac_addr
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return information about the device.""" """Return information about the device."""
_map = aiolifx().products.product_map _map = aiolifx().products.product_map
info = DeviceInfo( info = DeviceInfo(
identifiers={(LIFX_DOMAIN, self.unique_id)}, identifiers={(LIFX_DOMAIN, self.unique_id)},
connections={(dr.CONNECTION_NETWORK_MAC, self.bulb.mac_addr)}, connections={(dr.CONNECTION_NETWORK_MAC, self.get_mac_addr())},
manufacturer="LIFX", manufacturer="LIFX",
name=self.name, name=self.name,
) )
if model := (_map.get(self.bulb.product) or self.bulb.product) is not None:
if (model := (_map.get(self.bulb.product) or self.bulb.product)) is not None:
info[ATTR_MODEL] = str(model) info[ATTR_MODEL] = str(model)
if (version := self.bulb.host_firmware_version) is not None: if (version := self.bulb.host_firmware_version) is not None:
info[ATTR_SW_VERSION] = version info[ATTR_SW_VERSION] = version
return info return info
@property @property