Skip to content

Commit

Permalink
Merge pull request #23 from jfarmer08/Dev
Browse files Browse the repository at this point in the history
Updates to better support Color Bulbs
  • Loading branch information
jfarmer08 committed Sep 14, 2020
2 parents 1374b7c + 9d66a93 commit 8950a3e
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 254 deletions.
2 changes: 1 addition & 1 deletion custom_components/sengledapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def async_setup(hass, config):
-------------------------------------------------------------------
Sengled Bulb Home Assistant Integration Created from Config
Version: v0.1-beta.16
Version: v0.1-beta.17
This is a custom integration
If you have any issues with this you need to open an issue here:
https://github.com/jfarmer08/ha-sengledapi
Expand Down
8 changes: 8 additions & 0 deletions custom_components/sengledapi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
CONF_COUNTRY = "country"
CONF_TYPE = "wifi"
ATTRIBUTION = "Data provided by Sengled"

sengled_base_url = 'https://element.cloud.sengled.com/'
zigbee_url = 'zigbee/'
customer_url = 'customer/'
device_url = 'device/'
room_url = 'room/'
update_url = 'update/'
headers = {'Content-type': 'application/json'}
35 changes: 22 additions & 13 deletions custom_components/sengledapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def __init__(self, light):
self._color_temperature = light._color_temperature
self._color = light._color
self._device_rssi = light._device_rssi
self._rgb_color_r = light._rgb_color_r
self._rgb_color_g = light._rgb_color_g
self._rgb_color_b = light._rgb_color_b

@property
def name(self):
Expand All @@ -86,9 +89,6 @@ def device_state_attributes(self):
"device model": self._device_model,
"rssi": self._device_rssi,
"mac": self._device_mac,
"brightness": self._brightness,
"colorTemp": self._color_temperature,
"color": self._color,
}

@property
Expand All @@ -99,9 +99,12 @@ def color_temp(self):
@property
def hs_color(self):
"""Return the hs_color of the light."""
#_LOGGER.debug("FARMER::::::: %s", str(self._color))
a, b, c = self._color.split(":")
return colorutil.color_RGB_to_hs(int(a), int(b), int(c))
if self._device_model == "wificolora19":
a, b, c = self._color.split(":")
return colorutil.color_RGB_to_hs(int(a), int(b), int(c))
if self._device_model == "E11-N1EA" or "E11-U2E" or "E11-U3E" or "E1G-G8E" or "E12-N1E":
return colorutil.color_RGB_to_hs(self._rgb_color_r,self._rgb_color_g,self._rgb_color_b)
return ''

@property
def min_mireds(self):
Expand All @@ -115,11 +118,7 @@ def max_mireds(self):

@property
def brightness(self):
"""Return the brightness of the light.
This method is optional. Removing it indicates to Home Assistant
that brightness is not supported for this light.
"""
"""Return the brightness of the light."""
return self._brightness

@property
Expand All @@ -134,8 +133,8 @@ def supported_features(self):
features = SUPPORT_BRIGHTNESS
if self._device_model == "wifia19":
features = SUPPORT_BRIGHTNESS
if self._device_model == "E11-N1EA":
features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP
if self._device_model == "E11-N1EA" or "E11-U2E" or "E11-U3E" or "E1G-G8E" or "E12-N1E":
features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR
return features

async def async_turn_on(self, **kwargs):
Expand Down Expand Up @@ -167,3 +166,13 @@ async def async_update(self):
self._brightness = self._light._brightness
self._color_temperature = self._light._color_temperature
self._color = self._light._color

@property
def device_info(self):
"""Return the device info."""
return {
"name": self._name,
"identifiers": {(DOMAIN, self._device_mac)},
"model": self._device_model,
"manufacturer": "Sengled",
}
Empty file.
47 changes: 14 additions & 33 deletions custom_components/sengledapi/sengledapi/bulbs/sengled_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@


class SengledBulb:
def __init__(
self,
api,
device_mac,
friendly_name,
state,
device_model,
brightness,
device_rssi,
isonline,
jsession_id,
country,
):
def __init__(self,api,device_mac,friendly_name,state,device_model,isonline,jsession_id,country,):
_LOGGER.debug("SengledApi: Bulb %s initializing.", friendly_name)

self._api = api
Expand All @@ -30,23 +18,20 @@ def __init__(
self._avaliable = isonline
self._just_changed_state = False
self._device_model = device_model
self._brightness = int(brightness)
self._device_rssi = None
self._brightness = None
self._color = None
self._color_temperature = None
self._rgb_color_r = None
self._rgb_color_g = None
self._rgb_color_b = None
self._jsession_id = jsession_id
self._country = country
self._color_temperature = None
self._device_rssi = self.translate(int(device_rssi), 0, 5, 0, -100)

async def async_turn_on(self):
_LOGGER.debug(
"SengledApi: Bulb %s %s turning on.", self._friendly_name, self._device_mac
)
_LOGGER.debug("SengledApi: Bulb %s %s turning on.", self._friendly_name, self._device_mac)
self._just_changed_state = True
url = (
"https://"
+ self._country
+ "-elements.cloud.sengled.com/zigbee/device/deviceSetOnOff.json"
)
url = ("https://" + self._country + "-elements.cloud.sengled.com/zigbee/device/deviceSetOnOff.json")

payload = {"deviceUuid": self._device_mac, "onoff": "1"}

Expand All @@ -57,9 +42,7 @@ async def async_turn_on(self):
self._just_changed_state = True

async def async_set_brightness(self, brightness):
_LOGGER.debug(
"Bulb %s %s setting brightness.", self._friendly_name, self._device_mac
)
_LOGGER.debug("Bulb %s %s setting brightness.", self._friendly_name, self._device_mac)
self._state = True
self._just_changed_state = True

Expand Down Expand Up @@ -118,13 +101,11 @@ async def async_update(self):
for items in item["lampInfos"]:
if items["deviceUuid"] == self._device_mac:
self._friendly_name = items["attributes"]["name"]
self._state = (True if int(items["attributes"]["onoff"]) == 1 else False)
self._avaliable = (False if int(items["attributes"]["isOnline"]) == 0 else True)
self._device_rssi = self.translate(int(items["attributes"]["deviceRssi"]), 0, 5, 0, -100)
#Supported Features
self._brightness = int(items["attributes"]["brightness"])
self._state = (
True if int(items["attributes"]["onoff"]) == 1 else False
)
self._avaliable = (
False if int(items["attributes"]["isOnline"]) == 0 else True
)

def translate(self, value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

_LOGGER = logging.getLogger(__name__)
_LOGGER.debug("SengledApi: Initializing Sengled Bulb")
_LOGGER.debug("SengledApi: Initializing Sengled Flood Motion Bulb")


class SengledBulbFloodMotion:
Expand All @@ -15,8 +15,6 @@ def __init__(
friendly_name,
state,
device_model,
brightness,
device_rssi,
isonline,
jsession_id,
country,
Expand All @@ -30,12 +28,15 @@ def __init__(
self._avaliable = isonline
self._just_changed_state = False
self._device_model = device_model
self._brightness = int(brightness)
self._brightness = None
self._jsession_id = jsession_id
self._country = country
self._color_temperature = None
self._color = None
self._device_rssi = self.translate(int(device_rssi), 0, 5, 0, -100)
self._device_rssi = None
self._rgb_color_r = None
self._rgb_color_g = None
self._rgb_color_b = None

async def async_turn_on(self):
_LOGGER.debug(
Expand All @@ -58,7 +59,7 @@ async def async_turn_on(self):

async def async_set_brightness(self, brightness):
_LOGGER.debug(
"Bulb %s %s setting brightness.", self._friendly_name, self._device_mac
"SengledApi: Bulb %s Mac %s setting brightness.", self._friendly_name, self._device_mac
)
self._state = True
self._just_changed_state = True
Expand All @@ -75,7 +76,7 @@ async def async_set_brightness(self, brightness):

async def async_turn_off(self):
_LOGGER.debug(
"SengledApi: Bulb %s %s turning off.", self._friendly_name, self._device_mac
"SengledApi: Bulb %s Mac %s turning off.", self._friendly_name, self._device_mac
)
self._just_changed_state = True
url = (
Expand All @@ -96,12 +97,9 @@ def is_on(self):

async def async_update(self):
_LOGGER.debug(
"Sengled Bulb "
+ self._friendly_name
+ " "
+ self._device_mac
+ " updating."
"SengledApi: Bulb %s Mac %s Update Status.", self._friendly_name, self._device_mac
)

if self._just_changed_state:
self._just_changed_state = False
else:
Expand All @@ -112,18 +110,15 @@ async def async_update(self):

data = await self._api.async_do_request(url, payload, self._jsession_id)

_LOGGER.debug("Light " + self._friendly_name + " updating.")
for item in data["deviceInfos"]:
for items in item["lampInfos"]:
if items["deviceUuid"] == self._device_mac:
self._friendly_name = items["attributes"]["name"]
self._state = (True if int(items["attributes"]["onoff"]) == 1 else False)
self._avaliable = (False if int(items["attributes"]["isOnline"]) == 0 else True)
self._device_rssi = self.translate(int(items["attributes"]["deviceRssi"]), 0, 5, 0, -100)
#Support Features
self._brightness = int(items["attributes"]["brightness"])
self._state = (
True if int(items["attributes"]["onoff"]) == 1 else False
)
self._avaliable = (
False if int(items["attributes"]["isOnline"]) == 0 else True
)

def translate(self, value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
Expand Down
Loading

0 comments on commit 8950a3e

Please sign in to comment.