Skip to content

Commit

Permalink
Update for Access Token
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarmer08 committed Jun 10, 2020
1 parent f657018 commit 0a8ed2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions custom_components/sengledapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ATTR_COLOR_TEMP,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
Light,
LightEntity,
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -26,15 +26,15 @@

async def async_setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Sengled Light platform."""
_LOGGER.debug("""Creating new WyzeApi light component""")
_LOGGER.debug("""Creating new Sengled light component""")
# Add devices
add_entities(
SengledBulb(light)
for light in await hass.data[DOMAIN]["sengledapi_account"].async_list_bulbs()
)


class SengledBulb(Light):
class SengledBulb(LightEntity):
"""Representation of a Sengled Bulb."""

def __init__(self, light):
Expand Down
18 changes: 8 additions & 10 deletions custom_components/sengledapi/sengledapi/sengledapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from .sengled_bulb import SengledBulb
from .sengledapi_exceptions import SengledApiAccessToken

accesstoken = "JSESSIONID=cb3d6c2f-d626-48b2-9379-6d80445f5a80"


class SengledApi:
def __init__(self, user_name, password):
_LOGGER.debug("Sengled Api initializing.")
Expand All @@ -19,7 +16,7 @@ def __init__(self, user_name, password):
self._device_id = "740447d2-eb6e-11e9-81b4-2a2ae2dbcce4"
self._in_error_state = False
self._invalid_access_tokens = []

self._access_token = None
# Create device array
self._all_devices = []

Expand All @@ -28,7 +25,7 @@ async def async_init(self):
self._access_token = await self.async_login(
self._user_name, self._password, self._device_id
)
_LOGGER.debug(self._access_token)
_LOGGER.debug("sengledapi async_init" + self._access_token)

async def async_login(self, username, password, device_id):
_LOGGER.debug("Sengled Api log in async.")
Expand All @@ -44,7 +41,8 @@ async def async_login(self, username, password, device_id):

try:
access_token = "JSESSIONID=" + data["jsessionid"]
accesstoken = access_token
_LOGGER.debug("Sengled Api accessToken " + str(access_token))
self._access_token = access_token
return access_token
except:
return None
Expand All @@ -57,7 +55,7 @@ def is_valid_login(self):
def valid_access_token(self):
if self._access_token == None:
return "none"
return _access_token
return self._access_token

async def async_get_devices(self):
_LOGGER.debug("Sengled Api getting devices.")
Expand All @@ -66,7 +64,7 @@ async def async_get_devices(self):
"https://element.cloud.sengled.com/zigbee/device/getDeviceDetails.json"
)
payload = {}
data = await self.async_do_request(url, payload, accesstoken)
data = await self.async_do_request(url, payload, self._access_token)
self._all_devices = data["deviceInfos"]
return self._all_devices

Expand All @@ -86,7 +84,7 @@ async def async_list_bulbs(self):
("on" if device["attributes"]["onoff"] == 1 else "off"),
device["attributes"]["productCode"],
device["attributes"]["brightness"],
accesstoken,
self._access_token,
)
)

Expand All @@ -99,7 +97,7 @@ async def async_do_request(self, url, payload, accesstoken):
except:
return SengledRequest(url, payload).get_response(accesstoken)

###################################Login Request onley###############################
###################################Login Request only###############################
async def async_do_login_request(self, url, payload):
_LOGGER.debug("async_do_login_request - Sengled Api doing request.")
try:
Expand Down

0 comments on commit 0a8ed2a

Please sign in to comment.