Skip to content

Commit

Permalink
Paged aliases (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidoh authored Sep 25, 2023
1 parent 6543f60 commit bd1246c
Show file tree
Hide file tree
Showing 51 changed files with 1,994 additions and 653 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
.vscode/launch.json
/test/remote/settings.json
/test/remote/espmh.env
lib/Environment/wifi_credentials.h
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,12 @@ You can configure aliases or labels for a given _(Device Type, Device ID, Group

## REST API

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

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

[You can view generated documentation for the master branch here.](https://sidoh.github.io/esp8266_milight_hub/branches/latest)

[Docs for other branches can be found here](https://sidoh.github.io/esp8266_milight_hub)
API documentation is generated from the [OpenAPI spec](docs/openapi.yaml) using redoc.

## MQTT

Expand Down
4 changes: 2 additions & 2 deletions dist/index.html.gz.h

Large diffs are not rendered by default.

180 changes: 179 additions & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ x-tagGroups:
tags:
- System
- Settings
- name: Aliases
tags:
- Aliases
- name: Devices
tags:
- Device Control
Expand All @@ -38,6 +41,125 @@ x-tagGroups:
- Transitions

paths:
/aliases:
post:
tags:
- Aliases
summary: Create a new alias
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Alias'
responses:
'201':
description: Alias created successfully
content:
application/json:
# will only respond with the created ID
schema:
type: object
properties:
id:
type: integer
get:
tags:
- Aliases
summary: Get all aliases
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
aliases:
type: array
items:
$ref: '#/components/schemas/Alias'
page:
type: integer
count:
type: integer
num_pages:
type: integer
/aliases/{id}:
put:
tags:
- Aliases
summary: Update an alias by ID
parameters:
- name: id
in: path
required: true
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Alias'
responses:
'200':
description: Alias updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/BooleanResponse'
delete:
tags:
- Aliases
summary: Delete an alias by ID
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
description: Alias deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/BooleanResponse'
/aliases.bin:
get:
tags:
- Aliases
summary: Download a backup of all aliases in a binary format
responses:
'200':
description: Successful operation
content:
application/octet-stream:
schema:
type: string
format: binary
post:
tags:
- Aliases
summary: Upload a backup of all aliases in CSV format
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
responses:
'201':
description: Backup uploaded and aliases restored successfully
content:
application/json:
schema:
$ref: '#/components/schemas/BooleanResponse'
/about:
get:
tags:
Expand All @@ -50,6 +172,45 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/About'
/backup:
post:
tags:
- System
summary: Restore a backup
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
responses:
400:
description: error
content:
application/json:
schema:
$ref: '#/components/schemas/BooleanResponse'
201:
description: Backup uploaded and settings restored successfully
content:
application/json:
schema:
$ref: '#/components/schemas/BooleanResponse'
get:
tags:
- System
summary: Download a backup of all settings
responses:
200:
description: success
content:
application/octet-stream:
schema:
type: string
format: binary
/remote_configs:
get:
tags:
Expand Down Expand Up @@ -491,6 +652,19 @@ components:
$ref: '#/components/schemas/RemoteType'
required: true
schemas:
Alias:
type: object
properties:
alias:
type: string
id:
type: integer
device_id:
type: integer
group_id:
type: integer
device_type:
type: string
State:
description: "On/Off state"
type: string
Expand Down Expand Up @@ -997,7 +1171,11 @@ components:
$ref: '#/components/schemas/GroupStateField'
group_id_aliases:
type: object
description: Keys are aliases, values are 3-long arrays with same schema as items in `device_ids`.
description: |
DEPRECATED (use /aliases routes instead)
Keys are aliases, values are 3-long arrays with same schema as items in `device_ids`.
deprecated: true
example:
alias1: [1234, 'rgb_cct', 1]
alias2: [1234, 'rgb_cct', 2]
Expand Down
22 changes: 11 additions & 11 deletions lib/DataStructures/LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LinkedList {
Unlink and link the LinkedList correcly;
Increment _size
*/
virtual bool add(int index, T);
virtual bool add(size_t index, T);
/*
Adds a T object in the end of the LinkedList;
Increment _size;
Expand All @@ -60,13 +60,13 @@ class LinkedList {
Set the object at index, with T;
Increment _size;
*/
virtual bool set(int index, T);
virtual bool set(size_t index, T);
/*
Remove object at index;
If index is not reachable, returns false;
else, decrement _size
*/
virtual T remove(int index);
virtual T remove(size_t index);
virtual void remove(ListNode<T>* node);
/*
Remove last object;
Expand All @@ -81,14 +81,14 @@ class LinkedList {
Return Element if accessible,
else, return false;
*/
virtual T get(int index);
virtual T get(size_t index);

/*
Clear the entire array
*/
virtual void clear();

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

template<typename T>
ListNode<T>* LinkedList<T>::getNode(int index){
ListNode<T>* LinkedList<T>::getNode(size_t index){

int _pos = 0;
size_t _pos = 0;
ListNode<T>* current = root;

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

template<typename T>
bool LinkedList<T>::add(int index, T _t){
bool LinkedList<T>::add(size_t index, T _t){

if(index >= _size)
return add(_t);
Expand Down Expand Up @@ -226,7 +226,7 @@ bool LinkedList<T>::unshift(T _t){
}

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

template<typename T>
T LinkedList<T>::remove(int index){
T LinkedList<T>::remove(size_t index){
if (index < 0 || index >= _size)
{
return T();
Expand All @@ -325,7 +325,7 @@ T LinkedList<T>::remove(int index){


template<typename T>
T LinkedList<T>::get(int index){
T LinkedList<T>::get(size_t index){
ListNode<T> *tmp = getNode(index);

return (tmp ? tmp->data : T());
Expand Down
16 changes: 16 additions & 0 deletions lib/Environment/ProjectFS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by chris on 9/14/2023.
//

#ifndef ESP8266_MILIGHT_HUB_PROJECTFS_H
#define ESP8266_MILIGHT_HUB_PROJECTFS_H

#ifdef MILIGHT_USE_LITTLE_FS
#include <LittleFS.h>
#define ProjectFS LittleFS
#else
#include <FS.h>
#define ProjectFS SPIFFS
#endif

#endif //ESP8266_MILIGHT_HUB_PROJECTFS_H
36 changes: 36 additions & 0 deletions lib/Environment/ProjectWifi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Created by chris on 9/17/2023.
//

#ifndef ESP8266_MILIGHT_HUB_PROJECTWIFI_H
#define ESP8266_MILIGHT_HUB_PROJECTWIFI_H

#if __has_include(<wifi_credentials.h>)
#include <wifi_credentials.h>
#endif

#if defined(ESPMH_WIFI_SSID) && defined(ESPMH_WIFI_PASSWORD)
#define ESPMH_SETUP_WIFI(settings) { \
Serial.println(F(">>> ESPMH_WIFI_SETUP() <<<"));\
if (settings.wifiStaticIP.length() > 0) { \
Serial.printf_P(PSTR("Configuring static IP...%s\n"), settings.wifiStaticIP.c_str()); \
IPAddress _ip, _subnet, _gw;\
_ip.fromString(settings.wifiStaticIP);\
_subnet.fromString(settings.wifiStaticIPNetmask);\
_gw.fromString(settings.wifiStaticIPGateway);\
WiFi.config(_ip, _gw, _subnet);\
};\
WiFi.begin(ESPMH_WIFI_SSID, ESPMH_WIFI_PASSWORD); \
Serial.printf_P(PSTR("Connecting to %s...\n"), ESPMH_WIFI_SSID); \
while (WiFi.status() != WL_CONNECTED) {\
delay(500);\
Serial.print(".");\
}\
Serial.printf_P(PSTR("Connected to: %s with IP: "), ESPMH_WIFI_SSID); \
Serial.println(WiFi.localIP()); \
}
#else
#define ESPMH_SETUP_WIFI(settings) { }
#endif

#endif //ESP8266_MILIGHT_HUB_PROJECTWIFI_H
Loading

0 comments on commit bd1246c

Please sign in to comment.