Skip to content

Commit bd1246c

Browse files
authored
Paged aliases (#801)
1 parent 6543f60 commit bd1246c

51 files changed

Lines changed: 1994 additions & 653 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
.vscode/launch.json
1616
/test/remote/settings.json
1717
/test/remote/espmh.env
18+
lib/Environment/wifi_credentials.h

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,12 @@ You can configure aliases or labels for a given _(Device Type, Device ID, Group
125125

126126
## REST API
127127

128-
The REST API is specified using the [OpenAPI v3](https://swagger.io/docs/specification/about/) specification.
128+
Generated API documentation is available here:
129129

130-
[openapi.yaml](docs/openapi.yaml) contains the raw spec.
130+
* [latest version](https://sidoh.github.io/esp8266_milight_hub/branches/latest)
131+
* [all versions](https://sidoh.github.io/esp8266_milight_hub)
131132

132-
[You can view generated documentation for the master branch here.](https://sidoh.github.io/esp8266_milight_hub/branches/latest)
133-
134-
[Docs for other branches can be found here](https://sidoh.github.io/esp8266_milight_hub)
133+
API documentation is generated from the [OpenAPI spec](docs/openapi.yaml) using redoc.
135134

136135
## MQTT
137136

dist/index.html.gz.h

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/openapi.yaml

Lines changed: 179 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ x-tagGroups:
2828
tags:
2929
- System
3030
- Settings
31+
- name: Aliases
32+
tags:
33+
- Aliases
3134
- name: Devices
3235
tags:
3336
- Device Control
@@ -38,6 +41,125 @@ x-tagGroups:
3841
- Transitions
3942

4043
paths:
44+
/aliases:
45+
post:
46+
tags:
47+
- Aliases
48+
summary: Create a new alias
49+
requestBody:
50+
required: true
51+
content:
52+
application/json:
53+
schema:
54+
$ref: '#/components/schemas/Alias'
55+
responses:
56+
'201':
57+
description: Alias created successfully
58+
content:
59+
application/json:
60+
# will only respond with the created ID
61+
schema:
62+
type: object
63+
properties:
64+
id:
65+
type: integer
66+
get:
67+
tags:
68+
- Aliases
69+
summary: Get all aliases
70+
responses:
71+
'200':
72+
description: Successful operation
73+
content:
74+
application/json:
75+
schema:
76+
type: object
77+
properties:
78+
aliases:
79+
type: array
80+
items:
81+
$ref: '#/components/schemas/Alias'
82+
page:
83+
type: integer
84+
count:
85+
type: integer
86+
num_pages:
87+
type: integer
88+
/aliases/{id}:
89+
put:
90+
tags:
91+
- Aliases
92+
summary: Update an alias by ID
93+
parameters:
94+
- name: id
95+
in: path
96+
required: true
97+
schema:
98+
type: integer
99+
requestBody:
100+
required: true
101+
content:
102+
application/json:
103+
schema:
104+
$ref: '#/components/schemas/Alias'
105+
responses:
106+
'200':
107+
description: Alias updated successfully
108+
content:
109+
application/json:
110+
schema:
111+
$ref: '#/components/schemas/BooleanResponse'
112+
delete:
113+
tags:
114+
- Aliases
115+
summary: Delete an alias by ID
116+
parameters:
117+
- name: id
118+
in: path
119+
required: true
120+
schema:
121+
type: integer
122+
responses:
123+
'200':
124+
description: Alias deleted successfully
125+
content:
126+
application/json:
127+
schema:
128+
$ref: '#/components/schemas/BooleanResponse'
129+
/aliases.bin:
130+
get:
131+
tags:
132+
- Aliases
133+
summary: Download a backup of all aliases in a binary format
134+
responses:
135+
'200':
136+
description: Successful operation
137+
content:
138+
application/octet-stream:
139+
schema:
140+
type: string
141+
format: binary
142+
post:
143+
tags:
144+
- Aliases
145+
summary: Upload a backup of all aliases in CSV format
146+
requestBody:
147+
required: true
148+
content:
149+
multipart/form-data:
150+
schema:
151+
type: object
152+
properties:
153+
file:
154+
type: string
155+
format: binary
156+
responses:
157+
'201':
158+
description: Backup uploaded and aliases restored successfully
159+
content:
160+
application/json:
161+
schema:
162+
$ref: '#/components/schemas/BooleanResponse'
41163
/about:
42164
get:
43165
tags:
@@ -50,6 +172,45 @@ paths:
50172
application/json:
51173
schema:
52174
$ref: '#/components/schemas/About'
175+
/backup:
176+
post:
177+
tags:
178+
- System
179+
summary: Restore a backup
180+
requestBody:
181+
content:
182+
multipart/form-data:
183+
schema:
184+
type: object
185+
properties:
186+
file:
187+
type: string
188+
format: binary
189+
responses:
190+
400:
191+
description: error
192+
content:
193+
application/json:
194+
schema:
195+
$ref: '#/components/schemas/BooleanResponse'
196+
201:
197+
description: Backup uploaded and settings restored successfully
198+
content:
199+
application/json:
200+
schema:
201+
$ref: '#/components/schemas/BooleanResponse'
202+
get:
203+
tags:
204+
- System
205+
summary: Download a backup of all settings
206+
responses:
207+
200:
208+
description: success
209+
content:
210+
application/octet-stream:
211+
schema:
212+
type: string
213+
format: binary
53214
/remote_configs:
54215
get:
55216
tags:
@@ -491,6 +652,19 @@ components:
491652
$ref: '#/components/schemas/RemoteType'
492653
required: true
493654
schemas:
655+
Alias:
656+
type: object
657+
properties:
658+
alias:
659+
type: string
660+
id:
661+
type: integer
662+
device_id:
663+
type: integer
664+
group_id:
665+
type: integer
666+
device_type:
667+
type: string
494668
State:
495669
description: "On/Off state"
496670
type: string
@@ -997,7 +1171,11 @@ components:
9971171
$ref: '#/components/schemas/GroupStateField'
9981172
group_id_aliases:
9991173
type: object
1000-
description: Keys are aliases, values are 3-long arrays with same schema as items in `device_ids`.
1174+
description: |
1175+
DEPRECATED (use /aliases routes instead)
1176+
1177+
Keys are aliases, values are 3-long arrays with same schema as items in `device_ids`.
1178+
deprecated: true
10011179
example:
10021180
alias1: [1234, 'rgb_cct', 1]
10031181
alias2: [1234, 'rgb_cct', 2]

lib/DataStructures/LinkedList.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LinkedList {
4545
Unlink and link the LinkedList correcly;
4646
Increment _size
4747
*/
48-
virtual bool add(int index, T);
48+
virtual bool add(size_t index, T);
4949
/*
5050
Adds a T object in the end of the LinkedList;
5151
Increment _size;
@@ -60,13 +60,13 @@ class LinkedList {
6060
Set the object at index, with T;
6161
Increment _size;
6262
*/
63-
virtual bool set(int index, T);
63+
virtual bool set(size_t index, T);
6464
/*
6565
Remove object at index;
6666
If index is not reachable, returns false;
6767
else, decrement _size
6868
*/
69-
virtual T remove(int index);
69+
virtual T remove(size_t index);
7070
virtual void remove(ListNode<T>* node);
7171
/*
7272
Remove last object;
@@ -81,14 +81,14 @@ class LinkedList {
8181
Return Element if accessible,
8282
else, return false;
8383
*/
84-
virtual T get(int index);
84+
virtual T get(size_t index);
8585

8686
/*
8787
Clear the entire array
8888
*/
8989
virtual void clear();
9090

91-
ListNode<T>* getNode(int index);
91+
ListNode<T>* getNode(size_t index);
9292
virtual void spliceToFront(ListNode<T>* node);
9393
ListNode<T>* getHead() { return root; }
9494
T getLast() const { return last == NULL ? T() : last->data; }
@@ -145,9 +145,9 @@ LinkedList<T>::~LinkedList()
145145
*/
146146

147147
template<typename T>
148-
ListNode<T>* LinkedList<T>::getNode(int index){
148+
ListNode<T>* LinkedList<T>::getNode(size_t index){
149149

150-
int _pos = 0;
150+
size_t _pos = 0;
151151
ListNode<T>* current = root;
152152

153153
while(_pos < index && current){
@@ -164,7 +164,7 @@ size_t LinkedList<T>::size() const{
164164
}
165165

166166
template<typename T>
167-
bool LinkedList<T>::add(int index, T _t){
167+
bool LinkedList<T>::add(size_t index, T _t){
168168

169169
if(index >= _size)
170170
return add(_t);
@@ -226,7 +226,7 @@ bool LinkedList<T>::unshift(T _t){
226226
}
227227

228228
template<typename T>
229-
bool LinkedList<T>::set(int index, T _t){
229+
bool LinkedList<T>::set(size_t index, T _t){
230230
// Check if index position is in bounds
231231
if(index < 0 || index >= _size)
232232
return false;
@@ -299,7 +299,7 @@ void LinkedList<T>::remove(ListNode<T>* node){
299299
}
300300

301301
template<typename T>
302-
T LinkedList<T>::remove(int index){
302+
T LinkedList<T>::remove(size_t index){
303303
if (index < 0 || index >= _size)
304304
{
305305
return T();
@@ -325,7 +325,7 @@ T LinkedList<T>::remove(int index){
325325

326326

327327
template<typename T>
328-
T LinkedList<T>::get(int index){
328+
T LinkedList<T>::get(size_t index){
329329
ListNode<T> *tmp = getNode(index);
330330

331331
return (tmp ? tmp->data : T());

lib/Environment/ProjectFS.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Created by chris on 9/14/2023.
3+
//
4+
5+
#ifndef ESP8266_MILIGHT_HUB_PROJECTFS_H
6+
#define ESP8266_MILIGHT_HUB_PROJECTFS_H
7+
8+
#ifdef MILIGHT_USE_LITTLE_FS
9+
#include <LittleFS.h>
10+
#define ProjectFS LittleFS
11+
#else
12+
#include <FS.h>
13+
#define ProjectFS SPIFFS
14+
#endif
15+
16+
#endif //ESP8266_MILIGHT_HUB_PROJECTFS_H

lib/Environment/ProjectWifi.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Created by chris on 9/17/2023.
3+
//
4+
5+
#ifndef ESP8266_MILIGHT_HUB_PROJECTWIFI_H
6+
#define ESP8266_MILIGHT_HUB_PROJECTWIFI_H
7+
8+
#if __has_include(<wifi_credentials.h>)
9+
#include <wifi_credentials.h>
10+
#endif
11+
12+
#if defined(ESPMH_WIFI_SSID) && defined(ESPMH_WIFI_PASSWORD)
13+
#define ESPMH_SETUP_WIFI(settings) { \
14+
Serial.println(F(">>> ESPMH_WIFI_SETUP() <<<"));\
15+
if (settings.wifiStaticIP.length() > 0) { \
16+
Serial.printf_P(PSTR("Configuring static IP...%s\n"), settings.wifiStaticIP.c_str()); \
17+
IPAddress _ip, _subnet, _gw;\
18+
_ip.fromString(settings.wifiStaticIP);\
19+
_subnet.fromString(settings.wifiStaticIPNetmask);\
20+
_gw.fromString(settings.wifiStaticIPGateway);\
21+
WiFi.config(_ip, _gw, _subnet);\
22+
};\
23+
WiFi.begin(ESPMH_WIFI_SSID, ESPMH_WIFI_PASSWORD); \
24+
Serial.printf_P(PSTR("Connecting to %s...\n"), ESPMH_WIFI_SSID); \
25+
while (WiFi.status() != WL_CONNECTED) {\
26+
delay(500);\
27+
Serial.print(".");\
28+
}\
29+
Serial.printf_P(PSTR("Connected to: %s with IP: "), ESPMH_WIFI_SSID); \
30+
Serial.println(WiFi.localIP()); \
31+
}
32+
#else
33+
#define ESPMH_SETUP_WIFI(settings) { }
34+
#endif
35+
36+
#endif //ESP8266_MILIGHT_HUB_PROJECTWIFI_H

0 commit comments

Comments
 (0)