Skip to content

Commit

Permalink
added getModelConfig for auto kelvin map
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidy committed May 1, 2021
1 parent e5898a1 commit 7f0a27c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
53 changes: 38 additions & 15 deletions pywizlight/bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
WizLightConnectionError,
WizLightNotKnownBulb,
WizLightTimeOutError,
WizLightMethodeNotFound,
)
from pywizlight.scenes import SCENES

Expand Down Expand Up @@ -174,6 +175,9 @@ def get_extended_white_range(self) -> list:
"""Get the value of the extende whiteRange property."""
if "extRange" in self.pilotResult:
return self.pilotResult["extRange"]
# New after v1.22 FW - "cctRange":[2200,2700,6500,6500]
elif "cctRange" in self.pilotResult:
return self.pilotResult["cctRange"]
else:
return None

Expand Down Expand Up @@ -287,6 +291,8 @@ async def get_bulbtype(self) -> BulbType:
# 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,
Expand All @@ -303,23 +309,17 @@ async def get_bulbtype(self) -> BulbType:
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.kelvin_range = KelvinRange(min=_kelvin[0], max=_kelvin[1])
_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.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
# RGB supports effects but only "some"
Expand All @@ -341,12 +341,22 @@ async def getWhiteRange(self):

async def getExtendedWhiteRange(self):
"""Read extended withe range from the RGB bulb."""
resp = await self.getUserConfig()

# First for FW > 1.22
resp = await self.getModelConfig()
if resp is not None and "result" in resp and self.extwhiteRange is None:
self.extwhiteRange = PilotParser(resp["result"]).get_extended_white_range()
return self.extwhiteRange
else:
self.extwhiteRange = None
return self.extwhiteRange
# For old FW < 1.22
resp = await self.getUserConfig()
if "result" in resp and self.extwhiteRange is None:
self.extwhiteRange = PilotParser(
resp["result"]
).get_extended_white_range()
return self.extwhiteRange
else:
self.extwhiteRange = None

async def getSupportedScenes(self):
"""Return the supported scenes based on type.
Expand Down Expand Up @@ -442,6 +452,16 @@ async def getBulbConfig(self):
message = r'{"method":"getSystemConfig","params":{}}'
return await self.sendUDPMessage(message)

async def getModelConfig(self):
"""Return the new model capabilities from the bulb.
Only available in bulb FW >1.22!
"""
try:
message = r'{"method":"getModelConfig","params":{}}'
return await self.sendUDPMessage(message)
except WizLightMethodeNotFound:
return None

async def getUserConfig(self):
"""Return the user configuration from the bulb."""
message = r'{"method":"getUserConfig","params":{}}'
Expand Down Expand Up @@ -532,6 +552,9 @@ async def sendUDPMessage(self, message):
)
)
return resp
else:
# exception should be created
raise ValueError("Can't read response from the bulb. Debug:", resp)
elif resp["error"]["code"] == -32601:
raise WizLightMethodeNotFound(
"Cant found the methode. Maybe older bulb FW?"
)
# exception should be created
raise ValueError("Can't read response from the bulb. Debug:", resp)
6 changes: 6 additions & 0 deletions pywizlight/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ class WizLightNotKnownBulb(WizLightError):
"""The bulb type is not known to the pywizlight."""

pass


class WizLightMethodeNotFound(WizLightError):
"""The the called bulb function is not available."""

pass

0 comments on commit 7f0a27c

Please sign in to comment.