ci(pre-commit): Apply automatic fixes
This commit is contained in:
parent
ae274ee897
commit
ddf8c42af3
3 changed files with 40 additions and 76 deletions
|
|
@ -41,10 +41,8 @@ uint8_t button = BOOT_PIN;
|
|||
ZigbeeDimmableLight zbDimmableLight = ZigbeeDimmableLight(ZIGBEE_LIGHT_ENDPOINT);
|
||||
|
||||
/********************* RGB LED functions **************************/
|
||||
void setLight(bool state, uint8_t level)
|
||||
{
|
||||
if (!state)
|
||||
{
|
||||
void setLight(bool state, uint8_t level) {
|
||||
if (!state) {
|
||||
rgbLedWrite(led, 0, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
|
@ -52,12 +50,10 @@ void setLight(bool state, uint8_t level)
|
|||
}
|
||||
|
||||
// Create a task on identify call to handle the identify function
|
||||
void identify(uint16_t time)
|
||||
{
|
||||
void identify(uint16_t time) {
|
||||
static uint8_t blink = 1;
|
||||
log_d("Identify called for %d seconds", time);
|
||||
if (time == 0)
|
||||
{
|
||||
if (time == 0) {
|
||||
// If identify time is 0, stop blinking and restore light as it was used for identify
|
||||
zbDimmableLight.restoreLight();
|
||||
return;
|
||||
|
|
@ -67,8 +63,7 @@ void identify(uint16_t time)
|
|||
}
|
||||
|
||||
/********************* Arduino functions **************************/
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Init RMT and leave light OFF
|
||||
|
|
@ -91,34 +86,28 @@ void setup()
|
|||
Zigbee.addEndpoint(&zbDimmableLight);
|
||||
|
||||
// When all EPs are registered, start Zigbee in End Device mode
|
||||
if (!Zigbee.begin())
|
||||
{
|
||||
if (!Zigbee.begin()) {
|
||||
Serial.println("Zigbee failed to start!");
|
||||
Serial.println("Rebooting...");
|
||||
ESP.restart();
|
||||
}
|
||||
Serial.println("Connecting to network");
|
||||
while (!Zigbee.connected())
|
||||
{
|
||||
while (!Zigbee.connected()) {
|
||||
Serial.print(".");
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
// Checking button for factory reset
|
||||
if (digitalRead(button) == LOW)
|
||||
{ // Push button pressed
|
||||
if (digitalRead(button) == LOW) { // Push button pressed
|
||||
// Key debounce handling
|
||||
delay(100);
|
||||
int startTime = millis();
|
||||
while (digitalRead(button) == LOW)
|
||||
{
|
||||
while (digitalRead(button) == LOW) {
|
||||
delay(50);
|
||||
if ((millis() - startTime) > 3000)
|
||||
{
|
||||
if ((millis() - startTime) > 3000) {
|
||||
// If key pressed for more than 3secs, factory reset Zigbee and reboot
|
||||
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
|
||||
delay(1000);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
#include "esp_zigbee_cluster.h"
|
||||
|
||||
ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint)
|
||||
{
|
||||
ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint) {
|
||||
_device_id = ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID;
|
||||
|
||||
zigbee_dimmable_light_cfg_t light_cfg = ZIGBEE_DEFAULT_DIMMABLE_LIGHT_CONFIG();
|
||||
|
|
@ -19,58 +18,41 @@ ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint)
|
|||
}
|
||||
|
||||
// set attribute method -> method overridden in child class
|
||||
void ZigbeeDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message)
|
||||
{
|
||||
void ZigbeeDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) {
|
||||
// check the data and call right method
|
||||
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF)
|
||||
{
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL)
|
||||
{
|
||||
if (_current_state != *(bool *)message->attribute.data.value)
|
||||
{
|
||||
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) {
|
||||
if (_current_state != *(bool *)message->attribute.data.value) {
|
||||
_current_state = *(bool *)message->attribute.data.value;
|
||||
lightChanged();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
log_w("Received message ignored. Attribute ID: %d not supported for On/Off Light", message->attribute.id);
|
||||
}
|
||||
}
|
||||
else if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL)
|
||||
{
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_U8)
|
||||
{
|
||||
if (_current_level != *(uint8_t *)message->attribute.data.value)
|
||||
{
|
||||
} else if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL) {
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
|
||||
if (_current_level != *(uint8_t *)message->attribute.data.value) {
|
||||
_current_level = *(uint8_t *)message->attribute.data.value;
|
||||
lightChanged();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
log_w("Received message ignored. Attribute ID: %d not supported for Level Control", message->attribute.id);
|
||||
// TODO: implement more attributes -> includes/zcl/esp_zigbee_zcl_level.h
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
log_w("Received message ignored. Cluster ID: %d not supported for dimmable Light", message->info.cluster);
|
||||
}
|
||||
}
|
||||
|
||||
void ZigbeeDimmableLight::lightChanged()
|
||||
{
|
||||
if (_on_light_change)
|
||||
{
|
||||
void ZigbeeDimmableLight::lightChanged() {
|
||||
if (_on_light_change) {
|
||||
_on_light_change(_current_state, _current_level);
|
||||
}
|
||||
}
|
||||
|
||||
void ZigbeeDimmableLight::setLight(bool state, uint8_t level)
|
||||
{
|
||||
void ZigbeeDimmableLight::setLight(bool state, uint8_t level) {
|
||||
// Update all attributes
|
||||
_current_state = state;
|
||||
_current_level = level;
|
||||
|
|
@ -81,25 +63,24 @@ void ZigbeeDimmableLight::setLight(bool state, uint8_t level)
|
|||
esp_zb_lock_acquire(portMAX_DELAY);
|
||||
// set on/off state
|
||||
esp_zb_zcl_set_attribute_val(
|
||||
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false);
|
||||
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false
|
||||
);
|
||||
// set level
|
||||
esp_zb_zcl_set_attribute_val(
|
||||
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &_current_level, false);
|
||||
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &_current_level, false
|
||||
);
|
||||
esp_zb_lock_release();
|
||||
}
|
||||
|
||||
void ZigbeeDimmableLight::setLightState(bool state)
|
||||
{
|
||||
void ZigbeeDimmableLight::setLightState(bool state) {
|
||||
setLight(state, _current_level);
|
||||
}
|
||||
|
||||
void ZigbeeDimmableLight::setLightLevel(uint8_t level)
|
||||
{
|
||||
void ZigbeeDimmableLight::setLightLevel(uint8_t level) {
|
||||
setLight(_current_state, level);
|
||||
}
|
||||
|
||||
esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_create(zigbee_dimmable_light_cfg_t *light_cfg)
|
||||
{
|
||||
esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_create(zigbee_dimmable_light_cfg_t *light_cfg) {
|
||||
esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_basic_cluster_create(&light_cfg->basic_cfg);
|
||||
esp_zb_attribute_list_t *esp_zb_identify_cluster = esp_zb_identify_cluster_create(&light_cfg->identify_cfg);
|
||||
esp_zb_attribute_list_t *esp_zb_groups_cluster = esp_zb_groups_cluster_create(&light_cfg->groups_cfg);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@
|
|||
*
|
||||
*
|
||||
*/
|
||||
typedef struct zigbee_dimmable_light_cfg_s
|
||||
{
|
||||
typedef struct zigbee_dimmable_light_cfg_s {
|
||||
esp_zb_basic_cluster_cfg_t basic_cfg; /*!< Basic cluster configuration, @ref esp_zb_basic_cluster_cfg_s */
|
||||
esp_zb_identify_cluster_cfg_t identify_cfg; /*!< Identify cluster configuration, @ref esp_zb_identify_cluster_cfg_s */
|
||||
esp_zb_groups_cluster_cfg_t groups_cfg; /*!< Groups cluster configuration, @ref esp_zb_groups_cluster_cfg_s */
|
||||
|
|
@ -65,18 +64,15 @@ typedef struct zigbee_dimmable_light_cfg_s
|
|||
}
|
||||
// clang-format on
|
||||
|
||||
class ZigbeeDimmableLight : public ZigbeeEP
|
||||
{
|
||||
class ZigbeeDimmableLight : public ZigbeeEP {
|
||||
public:
|
||||
ZigbeeDimmableLight(uint8_t endpoint);
|
||||
~ZigbeeDimmableLight();
|
||||
|
||||
void onLightChange(void (*callback)(bool, uint8_t))
|
||||
{
|
||||
void onLightChange(void (*callback)(bool, uint8_t)) {
|
||||
_on_light_change = callback;
|
||||
}
|
||||
void restoreLight()
|
||||
{
|
||||
void restoreLight() {
|
||||
lightChanged();
|
||||
}
|
||||
|
||||
|
|
@ -84,12 +80,10 @@ public:
|
|||
void setLightLevel(uint8_t level);
|
||||
void setLight(bool state, uint8_t level);
|
||||
|
||||
bool getLightState()
|
||||
{
|
||||
bool getLightState() {
|
||||
return _current_state;
|
||||
}
|
||||
uint8_t getLightLevel()
|
||||
{
|
||||
uint8_t getLightLevel() {
|
||||
return _current_level;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue