Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complemented low control #84

Closed
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fe876e5
Addition of several missing rest calls
Anders-Holst Oct 12, 2021
ba86573
Make firmware_update compatible with Generation II
Anders-Holst Oct 12, 2021
ee3a0c2
Enable relative values in set_brightness
Anders-Holst Oct 12, 2021
4b68c0e
Enable options in set_network_mode_ap and _station
Anders-Holst Oct 12, 2021
daa5850
Making all rest calls consistent vrt validation and return
Anders-Holst Oct 12, 2021
b66c289
More flexible parameters to set_mqtt_config
Anders-Holst Oct 25, 2021
88c5b7c
Make encrypt_wifi_password work also with python3
Anders-Holst Oct 25, 2021
e76cddf
Adjusted after comments
Anders-Holst Oct 26, 2021
4cc9f9e
Merge branch 'scrool:develop' into complemented-low-control
Anders-Holst Nov 14, 2021
78b1a4c
Addition of several missing rest calls
Anders-Holst Oct 12, 2021
3ec95a1
Make firmware_update compatible with Generation II
Anders-Holst Oct 12, 2021
e592f37
Enable relative values in set_brightness
Anders-Holst Oct 12, 2021
8132a49
Enable options in set_network_mode_ap and _station
Anders-Holst Oct 12, 2021
885d4d7
Making all rest calls consistent vrt validation and return
Anders-Holst Oct 12, 2021
5eb1136
More flexible parameters to set_mqtt_config
Anders-Holst Oct 25, 2021
04e6640
Make encrypt_wifi_password work also with python3
Anders-Holst Oct 25, 2021
0a9a258
Adjusted after comments
Anders-Holst Oct 26, 2021
4ee45c1
Run black on control.py
Anders-Holst Nov 14, 2021
c55e5ad
Hmm, some rebasing conflict wanted me to do commit again but nothing …
Anders-Holst Nov 14, 2021
811637a
Sorry, tried to undo last commit
Anders-Holst Nov 14, 2021
ac72519
Corrected import of security, and removed some old comments
Anders-Holst Nov 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions xled/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,40 +708,56 @@ def set_mqtt_config(self, br_host, br_port, client_id, user, interval):
assert all(key in app_response.keys() for key in required_keys)
return app_response

def set_network_mode_ap(self):
def set_network_mode_ap(self, password=None):
"""
Sets network mode to Access Point
If password is given, changes the Access Point password
scrool marked this conversation as resolved.
Show resolved Hide resolved
(after which you have to connect again with the new password)

:param str password: new password to set
:raises ApplicationError: on application error
:rtype: None
:rtype: :class:`~xled.response.ApplicationResponse`
"""
json_payload = {"mode": 2}
if password:
json_payload = {
"mode": 2,
"ap": {"password": password, "enc": 4}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this easier to read.

Since {"mode": 2} is always sent that could be a default. And only if a password is set we could add second dict entry - "ap".

}
else:
json_payload = {"mode": 2}
url = urljoin(self.base_url, "network/status")
response = self.session.post(url, json=json_payload)
app_response = ApplicationResponse(response)
required_keys = [u"code"]
assert all(key in app_response.keys() for key in required_keys)
return app_response

def set_network_mode_station(self, ssid, password):
def set_network_mode_station(self, ssid=None, password=None):
scrool marked this conversation as resolved.
Show resolved Hide resolved
"""
Sets network mode to Access Point
Sets network mode to Station
scrool marked this conversation as resolved.
Show resolved Hide resolved
The first time you need to provide an ssid and password for
the WIFI to connect to.

:param str ssid: SSID if the access point to connect to
:param str ssid: SSID of the access point to connect to
:param str password: password to use
:raises ApplicationError: on application error
:rtype: None
:rtype: :class:`~xled.response.ApplicationResponse`
"""
assert self.hw_address
encpassword = encrypt_wifi_password(password, self.hw_address)
json_payload = {
"mode": 1,
"station": {"dhcp": 1, "ssid": ssid, "encpassword": encpassword},
}
if ssid and password:
encpassword = xled.security.encrypt_wifi_password(password, self.hw_address)
json_payload = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - let's use default with single dict entry "mode": 1 and only if password and ssid are available add those.

"mode": 1,
"station": {"dhcp": 1, "ssid": ssid, "encpassword": encpassword},
}
else:
json_payload = {"mode": 1}
url = urljoin(self.base_url, "network/status")
response = self.session.post(url, json=json_payload)
app_response = ApplicationResponse(response)
required_keys = [u"code"]
assert all(key in app_response.keys() for key in required_keys)
return app_response

def set_playlist(self, entries):
"""
Expand Down