Merge pull request #8801 from s-hadinger/zigbee_june_20

Minor Zigbee changes
This commit is contained in:
Theo Arends 2020-06-27 15:06:58 +02:00 committed by GitHub
commit 5fe75496f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 32 deletions

View File

@ -230,7 +230,7 @@ const Z_AttributeConverter Z_PostProcess[] PROGMEM = {
{ Zstring, Cx0000, 0x0006, Z(DateCode), 1, Z_Nop },
{ Zenum8, Cx0000, 0x0007, Z(PowerSource), 1, Z_Nop },
{ Zstring, Cx0000, 0x4000, Z(SWBuildID), 1, Z_Nop },
{ Zunk, Cx0000, 0xFFFF, nullptr, 0, Z_Nop }, // Remove all other values
// { Zunk, Cx0000, 0xFFFF, nullptr, 0, Z_Nop }, // Remove all other values
// Cmd 0x0A - Cluster 0x0000, attribute 0xFF01 - proprietary
{ Zmap8, Cx0000, 0xFF01, nullptr, 0, Z_AqaraSensor }, // Occupancy (map8)
@ -1220,38 +1220,44 @@ int32_t Z_OccupancyCallback(uint16_t shortaddr, uint16_t groupaddr, uint16_t clu
// Aqara Cube
int32_t Z_AqaraCubeFunc(const class ZCLFrame *zcl, uint16_t shortaddr, JsonObject& json, const char *name, JsonVariant& value, const String &new_name, uint16_t cluster, uint16_t attr) {
json[new_name] = value; // copy the original value
int32_t val = value;
const __FlashStringHelper *aqara_cube = F("AqaraCube");
const __FlashStringHelper *aqara_cube_side = F("AqaraCubeSide");
const __FlashStringHelper *aqara_cube_from_side = F("AqaraCubeFromSide");
switch (val) {
case 0:
json[aqara_cube] = F("shake");
break;
case 2:
json[aqara_cube] = F("wakeup");
break;
case 3:
json[aqara_cube] = F("fall");
break;
case 64 ... 127:
json[aqara_cube] = F("flip90");
json[aqara_cube_side] = val % 8;
json[aqara_cube_from_side] = (val - 64) / 8;
break;
case 128 ... 132:
json[aqara_cube] = F("flip180");
json[aqara_cube_side] = val - 128;
break;
case 256 ... 261:
json[aqara_cube] = F("slide");
json[aqara_cube_side] = val - 256;
break;
case 512 ... 517:
json[aqara_cube] = F("tap");
json[aqara_cube_side] = val - 512;
break;
const char * modelId_c = zigbee_devices.getModelId(shortaddr); // null if unknown
String modelId((char*) modelId_c);
if (modelId.startsWith(F("lumi.sensor_cube."))) { // only for Aqara cube
int32_t val = value;
const __FlashStringHelper *aqara_cube = F("AqaraCube");
const __FlashStringHelper *aqara_cube_side = F("AqaraCubeSide");
const __FlashStringHelper *aqara_cube_from_side = F("AqaraCubeFromSide");
switch (val) {
case 0:
json[aqara_cube] = F("shake");
break;
case 2:
json[aqara_cube] = F("wakeup");
break;
case 3:
json[aqara_cube] = F("fall");
break;
case 64 ... 127:
json[aqara_cube] = F("flip90");
json[aqara_cube_side] = val % 8;
json[aqara_cube_from_side] = (val - 64) / 8;
break;
case 128 ... 132:
json[aqara_cube] = F("flip180");
json[aqara_cube_side] = val - 128;
break;
case 256 ... 261:
json[aqara_cube] = F("slide");
json[aqara_cube_side] = val - 256;
break;
case 512 ... 517:
json[aqara_cube] = F("tap");
json[aqara_cube_side] = val - 512;
break;
}
}
// Source: https://github.com/kirovilya/ioBroker.zigbee

View File

@ -111,6 +111,8 @@ const uint8_t ZIGBEE_LABEL_START_ROUTER = 13; // Start ZNP as router
const uint8_t ZIGBEE_LABEL_INIT_DEVICE = 14; // Init ZNP as end-device
const uint8_t ZIGBEE_LABEL_START_DEVICE = 15; // Start ZNP as end-device
const uint8_t ZIGBEE_LABEL_START_ROUTER_DEVICE = 16; // Start common to router and device
const uint8_t ZIGBEE_LABEL_BOOT_OK = 17; // MCU has rebooted
const uint8_t ZIGBEE_LABEL_BOOT_TIME_OUT = 18; // MCU has not rebooted
const uint8_t ZIGBEE_LABEL_FACT_RESET_ROUTER_DEVICE_POST = 19; // common post configuration for router and device
const uint8_t ZIGBEE_LABEL_READY = 20; // goto label 20 for main loop
const uint8_t ZIGBEE_LABEL_MAIN_LOOP = 21; // main loop
@ -421,8 +423,17 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
//ZI_MQTT_STATE(ZIGBEE_STATUS_BOOT, "Booting")
//ZI_LOG(LOG_LEVEL_INFO, D_LOG_ZIGBEE "rebooting device")
ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_BOOT_TIME_OUT) // give a second chance
ZI_SEND(ZBS_RESET) // reboot cc2530 just in case we rebooted ESP8266 but not cc2530
ZI_WAIT_RECV_FUNC(5000, ZBR_RESET, &Z_Reboot) // timeout 5s
ZI_GOTO(ZIGBEE_LABEL_BOOT_OK)
ZI_LABEL(ZIGBEE_LABEL_BOOT_TIME_OUT)
ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT)
ZI_SEND(ZBS_RESET) // reboot cc2530 just in case we rebooted ESP8266 but not cc2530
ZI_WAIT_RECV_FUNC(5000, ZBR_RESET, &Z_Reboot) // timeout 5s
ZI_LABEL(ZIGBEE_LABEL_BOOT_OK)
ZI_WAIT(100)
ZI_LOG(LOG_LEVEL_DEBUG, kCheckingDeviceConfiguration) // Log Debug: checking device configuration
ZI_SEND(ZBS_VERSION) // check ZNP software version