Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zsy056 committed Jun 11, 2023
1 parent 63352dd commit 0069e4e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "dueros_smarthome"
version = "0.0.8"
version = "0.0.9"
authors = [
{ name="Shaoyu Zhang", email="zsy056@gmail.com" },
]
Expand Down
2 changes: 2 additions & 0 deletions src/dueros_smarthome/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self, bduss: str, host: str = const.DEFAULT_HOST, schema: str = con
self._bduss = bduss
self._cookies = httpx.Cookies()
self._cookies.set(const.BDUSS_COOKIE_KEY, self._bduss, domain = self._host)
for key in const.ADDITIONAL_COOKIES:
self._cookies.set(key, const.ADDITIONAL_COOKIES[key], domain = self._host)

@property
def host(self):
Expand Down
4 changes: 3 additions & 1 deletion src/dueros_smarthome/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

DEFAULT_PAYLOAD_VERSION = 3

DEVICE_LIST_QUERY = "/saiya/smarthome/devicelist?form=h5_control&generalscene=2"
DEVICE_LIST_QUERY = "/saiya/smarthome/devicelist?from=h5_control&withscene=1&generalscene=3"
DEVICE_ACTION_QUERY = "/saiya/smarthome/directivesend?from=h5_control"

BDUSS_COOKIE_KEY = "BDUSS"
Expand All @@ -20,6 +20,8 @@
ATTRIBUTE = "attribute"
ATTRIBUTE_VALUE = "attributeValue"

ADDITIONAL_COOKIES = {"smarthome-curtain-device-detail-new": "1"}

STATUS = "status"
MSG = "msg"
LOGID = "logid"
Expand Down
44 changes: 30 additions & 14 deletions src/dueros_smarthome/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def timestamp_of_sample(self):

class ConnectivitySetting:
def __init__(self, connectivity_setting: dict):
self._connectivity = connectivity_setting[const.VALUE]
self._value = connectivity_setting[const.VALUE]
self._time = connectivity_setting[const.TIME]

@property
def connectivity(self):
return self._connectivity
def value(self):
return self._value

@property
def time(self):
Expand All @@ -49,12 +49,15 @@ def from_str(label: str):

class TurnOnStateSetting:
def __init__(self, turn_on_state_setting: dict):
self._turn_on_state = TurnOnState.from_str(turn_on_state_setting[const.VALUE])
if turn_on_state_setting[const.VALUE]:
self._value = TurnOnState.from_str(turn_on_state_setting[const.VALUE])
else:
self._value = None
self._time = turn_on_state_setting[const.TIME]

@property
def turn_on_state(self):
return self._turn_on_state
def value(self):
return self._value

@property
def time(self):
Expand Down Expand Up @@ -270,12 +273,15 @@ def percentage(self) -> int:

class BrightnessSetting:
def __init__(self, brightness_setting: dict):
self._brightness = Brightness(brightness_setting[const.VALUE])
if brightness_setting[const.VALUE]:
self._value = Brightness(brightness_setting[const.VALUE])
else:
self._value = None
self._time = brightness_setting[const.TIME]

@property
def brightness(self):
return self._brightness
def value(self):
return self._value

@property
def time(self):
Expand Down Expand Up @@ -307,12 +313,15 @@ def kelvin_max(self):

class ColorTemperatureInKelvinSetting:
def __init__(self, setting: dict):
self._color_temperature_in_kelvin = ColorTemperatureInKelvin(setting[const.VALUE])
if setting[const.VALUE]:
self._value = ColorTemperatureInKelvin(setting[const.VALUE])
else:
self._value = None
self._time = setting[const.TIME]

@property
def color_temperature_in_kelvin(self):
return self._color_temperature_in_kelvin
def value(self):
return self._value

@property
def time(self):
Expand Down Expand Up @@ -350,6 +359,8 @@ class ApplianceAttributes:
def __init__(self, attributes: dict):
if const.CONNECTIVITY in attributes:
self._connectivity = ConnectivityAttribute(attributes[const.CONNECTIVITY])
else:
self._connectivity = None

@property
def connectivity(self):
Expand Down Expand Up @@ -390,12 +401,12 @@ def icon_url(self):
class ApplianceModes:
def __init__(self, modes: dict):
if const.BRIGHTNESS_AND_COLOR_TEMPERATURE in modes:
self._brightness_and_color_temperature = {mode: BrightnessAndColorTemperatureMode(mode_setting) for (mode, mode_setting) in modes[const.BRIGHTNESS_AND_COLOR_TEMPERATURE]}
self._brightness_and_color_temperature = {mode: BrightnessAndColorTemperatureMode(modes[const.BRIGHTNESS_AND_COLOR_TEMPERATURE][mode]) for mode in modes[const.BRIGHTNESS_AND_COLOR_TEMPERATURE]}
else:
self._brightness_and_color_temperature = None

if const.BRIGHTNESS_AND_COLOR_TEMPERATURE_WITH_ICON in modes:
self._brightness_and_color_temperature_with_icon = {mode: BrightnessAndColorTemperatureWithIconMode(mode_setting) for (mode, mode_setting) in modes[const.BRIGHTNESS_AND_COLOR_TEMPERATURE_WITH_ICON]}
self._brightness_and_color_temperature_with_icon = {mode: BrightnessAndColorTemperatureWithIconMode(modes[const.BRIGHTNESS_AND_COLOR_TEMPERATURE_WITH_ICON][mode]) for mode in modes[const.BRIGHTNESS_AND_COLOR_TEMPERATURE_WITH_ICON]}
else:
self._brightness_and_color_temperature_with_icon = None

Expand Down Expand Up @@ -476,6 +487,7 @@ def __init__(self, appliance_info: dict):
self._room_id = appliance_info[const.ROOM_ID]
self._floor_id = appliance_info[const.FLOOR_ID]
self._attributes = ApplianceAttributes(appliance_info[const.ATTRIBUTES])
self._state_settings = ApplianceStateSettings(appliance_info[const.STATE_SETTING])
self._icon_urls = [icon_url for icon_url in appliance_info[const.ICON_URLS].values()]
self._status = appliance_info[const.STATUS]

Expand Down Expand Up @@ -539,6 +551,10 @@ def floor_id(self):
def attributes(self):
return self._attributes

@property
def state_settings(self):
return self._state_settings

@property
def icon_urls(self):
return self._icon_urls
Expand Down

0 comments on commit 0069e4e

Please sign in to comment.