Skip to content

Commit

Permalink
Correct issues with Colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarmer08 committed May 18, 2022
1 parent 931ab9c commit 3962c51
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
17 changes: 17 additions & 0 deletions custom_components/sengledapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ def __init__(self, light):
@property
def name(self):
"""Return the display name of this light."""
_LOGGER.debug("Light.py Name %s", self._name)
return self._name

@property
def unique_id(self):
_LOGGER.debug("Light.py unique_id %s", self._device_mac)
return self._device_mac

@property
def available(self):
"""Return the connection status of this light"""
_LOGGER.debug("Light.py _avaliable %s", self._avaliable)
return self._avaliable

@property
Expand All @@ -95,6 +98,11 @@ def extra_state_attributes(self):
"rssi": self._device_rssi,
"mac": self._device_mac,
"alarm status ": self._alarm_status,
"color": self._color,
"color Temp": self._color_temperature,
"color r": self._rgb_color_r,
"color g": self._rgb_color_g,
"color b": self._rgb_color_b,
}
else:
return {
Expand All @@ -104,11 +112,17 @@ def extra_state_attributes(self):
"device model": self._device_model,
"rssi": self._device_rssi,
"mac": self._device_mac,
"color": self._color,
"color Temp": self._color_temperature,
"color r": self._rgb_color_r,
"color g": self._rgb_color_g,
"color b": self._rgb_color_b,
}

@property
def color_temp(self):
"""Return the color_temp of the light."""
_LOGGER.debug("Light.py color_temp %s", self._color_temperature)
if self._color_temperature is None:
return colorutil.color_temperature_kelvin_to_mired(2000)
else:
Expand All @@ -117,6 +131,7 @@ def color_temp(self):
@property
def hs_color(self):
"""Return the hs_color of the light."""
_LOGGER.debug("Light.py hs_color %s", self._color)
if self._wifi_device:
a, b, c = self._color.split(":")
return colorutil.color_RGB_to_hs(int(a), int(b), int(c))
Expand All @@ -128,11 +143,13 @@ def hs_color(self):
@property
def brightness(self):
"""Return the brightness of the light."""
_LOGGER.debug("Light.py brightness %s", self._brightness)
return self._brightness

@property
def is_on(self):
"""Return true if light is on."""
_LOGGER.debug("Light.py is_on %s", self._state)
return self._state

@property
Expand Down
33 changes: 18 additions & 15 deletions custom_components/sengledapi/sengledapi/devices/bulbs/bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ async def async_set_brightness(self, brightness):
"""Set Bulb Brightness"""
if self._wifi_device:
_LOGGER.info(
"Wifi Bulb %s %s setting brightness.",
"Wifi Bulb %s %s setting brightness %s, This is from HA ",
self._friendly_name,
self._device_mac,
str(brightness),
)

brightness_precentage = round((brightness / 255) * 100)

_LOGGER.info(
"SengledApi: Wifi Color Bulb %s %s setting Brighness %s",
"SengledApi: Wifi Color Bulb %s %s setting Brighness %s, This is what we are setting Sengled API",
self._friendly_name,
self._device_mac,
str(brightness_precentage),
Expand Down Expand Up @@ -148,14 +149,20 @@ async def async_set_brightness(self, brightness):
)

async def async_color_temperature(self, color_temperature):
_LOGGER.info(
"Wifi Bulb %s %s setting color Temperature %s, This is from HA ",
self._friendly_name,
self._device_mac,
str(color_temperature),
)
"""Set Color Temperature"""
color_temperature_precentage = round(
self.translate(int(color_temperature), 200, 6500, 1, 100)
)

if self._wifi_device:
_LOGGER.info(
"SengledApi: Wifi Color Bulb %s %s Set Color Temperature %s",
"SengledApi: Wifi Color Bulb %s %s Set Color Temperature %s, This is what we are setting Sengled API",
self._friendly_name,
self._device_mac,
color_temperature_precentage,
Expand Down Expand Up @@ -256,13 +263,11 @@ def is_on(self):
async def async_update(self):
if self._wifi_device:
_LOGGER.info(
"SengledApi: Wifi Bulb "
+ self._friendly_name
+ " "
+ self._device_mac
+ " updating."
"SengledApi: Wifi Bulb %s %s is updating",
self._friendly_name,
self._device_mac,
)
if self._just_changed_state:
if not self._just_changed_state:
_LOGGER.info(
"SengledApi: Bulb State Change: %s", self._just_changed_state
)
Expand All @@ -277,7 +282,7 @@ async def async_update(self):
"SengledApi: Wifi Bulb " + self._friendly_name + " updating."
)
for item in data["deviceList"]:
_LOGGER.debug("SengledApi: Wifi Bulb update return " + str(item))
_LOGGER.debug("SengledApi: Wifi Bulb update return: %s", str(item))
bulbs.append(BulbProperty(self, item, True))
for items in bulbs:
if items.uuid == self._device_mac:
Expand All @@ -291,12 +296,10 @@ async def async_update(self):
(int(items.brightness) / 100) * 255
)
if self._support_color_temp:
self._color_temperature = round(
self.translate(
int(items.color_temperature), 0, 100, 2000, 6500
)
)
_LOGGER.debug("SengledApi: Wifi Bulb Colo Temp: %s", items.color_temperature)
self._color_temperature = round(self.translate(int(items.color_temperature), 0, 100, 2000, 6500))
if self._support_color:
_LOGGER.debug("SengledApi: Wifi Bulb Color: %s", items.color)
self._color = items.color
else:
_LOGGER.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def color_temperature(self):
for attr in self._attributes:
if attr["name"] == "colorTemperature":
return int(attr["value"])
return 2000
#return 2000
else:
if self._attributes["colorTemperature"]:
color_temperature = self._info["attributes"]["colorTemperature"]
Expand Down

0 comments on commit 3962c51

Please sign in to comment.