async def get_bulbtype(self) -> BulbType: """Retrun the bulb type as BulbType object.""" if self.bulbtype is None: bulb_config = await self.getBulbConfig() if "moduleName" in bulb_config["result"]: _bulbtype = bulb_config["result"]["moduleName"] # set the minimum features for dimmable bulbs (DW bulbs) # define the kelvin range _kelvin = await self.getExtendedWhiteRange() _bulb = BulbType( bulb_type=BulbClass.DW, name=_bulbtype, features=Features(brightness=True, color=False, effect=False, color_tmp=False), kelvin_range=None, ) try: # parse the features from name _identifier = _bulbtype.split("_")[1] # Throw exception if index can not be found except IndexError: raise WizLightNotKnownBulb( "The bulb type can not be determined!") # go an try to map extensions to the BulbTyp object # Color support # TODO: Wokaround - In bulb firmware version 1.22.0 the k-range was removed. if "RGB" in _identifier: if _kelvin: _bulb.kelvin_range = KelvinRange(min=_kelvin[0], max=_kelvin[1]) else: _bulb.kelvin_range = KelvinRange(min=2700, max=6500) _bulb.bulb_type = BulbClass.RGB _bulb.features.color = True # RGB supports effects and tuneabel white _bulb.features.effect = True _bulb.features.color_tmp = True # Non RGB but tunable white bulb if "TW" in _identifier: if _kelvin: _bulb.kelvin_range = KelvinRange(min=_kelvin[0], max=_kelvin[1]) else: _bulb.kelvin_range = KelvinRange(min=2700, max=6500) _bulb.bulb_type = BulbClass.TW _bulb.features.color_tmp = True # RGB supports effects but only "some" # TODO: Improve the mapping to supported effects _bulb.features.effect = True self.bulbtype = _bulb return _bulb raise WizLightNotKnownBulb("The bulb features can not be mapped!")
async def get_bulbtype(self) -> BulbType: """Retrun the bulb type as BulbType object.""" if self.bulbtype is None: bulb_config = await self.getBulbConfig() if "moduleName" in bulb_config["result"]: _bulbtype = bulb_config["result"]["moduleName"] # set the minimum features for dimmable bulbs (DW bulbs) # define the kelvin range _kelvin = await self.getExtendedWhiteRange() # use only first and last entry - [2200,2700,6500,6500] _kelvin = _kelvin[:: len(_kelvin) - 1] _bulb = BulbType( bulb_type=BulbClass.DW, name=_bulbtype, features=Features( brightness=True, color=False, effect=False, color_tmp=False ), kelvin_range=None, ) try: # parse the features from name _identifier = _bulbtype.split("_")[1] # Throw exception if index can not be found except IndexError: raise WizLightNotKnownBulb("The bulb type can not be determined!") # try to map extensions to the BulbTyp object # Color support if "RGB" in _identifier: _bulb.kelvin_range = KelvinRange(min=_kelvin[0], max=_kelvin[1]) _bulb.bulb_type = BulbClass.RGB _bulb.features.color = True # RGB supports effects and CCT _bulb.features.effect = True _bulb.features.color_tmp = True # Tunable white bulb; no RGB if "TW" in _identifier: _bulb.kelvin_range = KelvinRange(min=_kelvin[0], max=_kelvin[1]) _bulb.kelvin_range = KelvinRange(min=2700, max=6500) _bulb.bulb_type = BulbClass.TW _bulb.features.color_tmp = True # TW supports some effects only # TODO: Improve the mapping to supported effects _bulb.features.effect = True self.bulbtype = _bulb return _bulb raise WizLightNotKnownBulb("The bulb features can not be mapped!")
async def get_bulbtype(self) -> BulbType: """Retrun the bulb type as BulbType object.""" if self.bulbtype is None: bulb_config = await self.getBulbConfig() if "moduleName" in bulb_config["result"]: _bulbtype = bulb_config["result"]["moduleName"] # look for match in known bulbs for known_bulb in BulbLib.BULBLIST: if known_bulb.name == _bulbtype: # retrun the BulbType object return known_bulb raise WizLightNotKnownBulb("The bulb is unknown to the intergration.")
def from_data( module_name: str, kelvin_list: Optional[List[float]], fw_version: Optional[str], white_channels: Optional[int], white_to_color_ratio: Optional[int], type_id: Optional[int], ) -> "BulbType": if module_name: try: # parse the features from name _identifier = module_name.split("_")[1] # Throw exception if index can not be found except IndexError: raise WizLightNotKnownBulb( f"The bulb type could not be determined from the module name: {module_name}" ) if "RGB" in _identifier: # full RGB bulb bulb_type = BulbClass.RGB effect = True elif "TW" in _identifier: # Non RGB but tunable white bulb bulb_type = BulbClass.TW effect = True elif "SOCKET" in _identifier: # A smart socket bulb_type = BulbClass.SOCKET effect = False else: # Plain brightness-only bulb bulb_type = BulbClass.DW effect = "DH" in _identifier or "SH" in _identifier dual_head = "DH" in _identifier elif type_id is not None: if type_id not in KNOWN_TYPE_IDS: _LOGGER.warning( "Unknown typeId: %s, please report what kind of bulb " "this is at https://github.com/sbidy/pywizlight/issues/new", type_id, ) bulb_type = KNOWN_TYPE_IDS.get(type_id, BulbClass.DW) dual_head = False effect = True else: raise WizLightNotKnownBulb( f"The bulb type could not be determined from the module name: {module_name} or type_id" ) if kelvin_list: kelvin_range: Optional[KelvinRange] = KelvinRange( min=int(min(kelvin_list)), max=int(max(kelvin_list))) elif bulb_type in (BulbClass.RGB, BulbClass.TW): raise WizLightNotKnownBulb( f"Unable to determine required kelvin range for a {bulb_type.value} device" ) else: kelvin_range = None features = Features(**_BASE_FEATURE_MAP[bulb_type], dual_head=dual_head, effect=effect) return BulbType( bulb_type=bulb_type, name=module_name, features=features, kelvin_range=kelvin_range, fw_version=fw_version, white_channels=white_channels, white_to_color_ratio=white_to_color_ratio, )