Skip to content

Commit

Permalink
Merge remote-tracking branch 'swoopx/fp1'
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed May 24, 2022
2 parents 6499c08 + 9f7e46b commit a532f0f
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 5 deletions.
8 changes: 8 additions & 0 deletions devices/generic/items/state_presenceevent_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"schema": "resourceitem1.schema.json",
"id": "state/presenceevent",
"datatype": "String",
"access": "R",
"public": true,
"description": "Describes what current activity is associated with the current presence state"
}
208 changes: 208 additions & 0 deletions devices/xiaomi/xiaomi_rtczcgq11lm_fp1_presence_sensor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"schema": "devcap1.schema.json",
"manufacturername": "aqara",
"modelid": "lumi.motion.ac01",
"vendor": "Xiaomi",
"product": "Aqara FP1 presence sensor RTCZCGQ11LM",
"sleeper": false,
"status": "Gold",
"subdevices": [
{
"type": "$TYPE_PRESENCE_SENSOR",
"restapi": "/sensors",
"uuid": [
"$address.ext",
"0x01",
"0x0406"
],
"items": [
{
"name": "attr/id"
},
{
"name": "attr/lastannounced"
},
{
"name": "attr/lastseen"
},
{
"name": "attr/manufacturername"
},
{
"name": "attr/modelid"
},
{
"name": "attr/name"
},
{
"name": "attr/swversion",
"read": {
"at": "0x0006",
"cl": "0x0000",
"ep": 1,
"fn": "zcl"
},
"parse": {
"at": "0x0006",
"cl": "0x0000",
"ep": 1,
"eval": "Item.val = Attr.val",
"fn": "zcl"
}
},
{
"name": "attr/type"
},
{
"name": "attr/uniqueid"
},
{
"name": "config/triggerdistance",
"refresh.interval": 300,
"parse": {
"at": "0x0146",
"cl": "0xfcc0",
"ep": 1,
"eval": "if (Attr.val == 0) { Item.val = 'far' } else if (Attr.val == 1) { Item.val = 'medium' } else if (Attr.val == 2) { Item.val = 'near' } else { Item.val = 'unknown' }",
"fn": "zcl"
},
"read": {
"at": "0x0146",
"cl": "0xfcc0",
"ep": 1,
"fn": "zcl"
},
"write": {
"at": "0x0146",
"cl": "0xfcc0",
"dt": "0x20",
"ep": 1,
"eval": "if (Item.val == 'far') { 0 } else if (Item.val == 'medium') { 1 } else if (Item.val == 'near') { 2 }",
"fn": "zcl"
},
"values": [
["\"far\"", "Someone approaching is detected on high distance"],
["\"medium\"", "Someone approaching is detected on medium distance"],
["\"near\"", "Someone approaching is detected on low distance"]
],
"default": "far"
},
{
"name": "config/devicemode",
"refresh.interval": 300,
"parse": {
"at": "0x0144",
"cl": "0xfcc0",
"ep": 1,
"eval": "if (Attr.val == 0) { Item.val = 'undirected' } else if (Attr.val == 1) { Item.val = 'leftright' } else { Item.val = 'unknown' }",
"fn": "zcl"
},
"read": {
"at": "0x0144",
"cl": "0xfcc0",
"ep": 1,
"fn": "zcl"
},
"write": {
"at": "0x0144",
"cl": "0xfcc0",
"dt": "0x20",
"ep": 1,
"eval": "if (Item.val == 'undirected') { 0 } else if (Item.val == 'leftright') { 1 }",
"fn": "zcl"
},
"values": [
["\"undirected\"", "Undirected"],
["\"leftright\"", "Left and right"]
],
"default": "undirected"
},
{
"name": "config/on"
},
{
"name": "config/reachable"
},
{
"name": "config/resetpresence",
"parse": {
"at": "0xff07",
"ep": 1,
"eval": "Item.val = false",
"fn": "xiaomi:special",
"idx": "0x03"
},
"write": {
"at": "0x0157",
"cl": "0xfcc0",
"dt": "0x20",
"ep": 1,
"eval": "Item.val",
"fn": "zcl"
}
},
{
"name": "config/sensitivity",
"refresh.interval": 300,
"parse": {
"at": "0x010C",
"cl": "0xfcc0",
"ep": 1,
"eval": "Item.val = Attr.val",
"fn": "zcl"
},
"read": {
"at": "0x010C",
"cl": "0xfcc0",
"ep": 1,
"fn": "zcl"
},
"write": {
"at": "0x010C",
"cl": "0xfcc0",
"dt": "0x20",
"ep": 1,
"eval": "Item.val",
"fn": "zcl"
},
"values": [
[1, "Low"],
[2, "Medium"],
[3, "High"]
],
"default": 3
},
{
"name": "state/lastupdated"
},
{
"name": "state/presence",
"read": {
"fn": "none"
},
"parse": {
"at": "0x0143",
"cl": "0xfcc0",
"ep": 1,
"eval": "(Attr.val != 0 && Attr.val != 1 && Attr.val != 3 && Attr.val != 5) ? Item.val = true : Item.val = false",
"fn": "zcl"
}
},
{
"name": "state/presenceevent",
"read": {
"fn": "none"
},
"parse": {
"at": "0x0143",
"cl": "0xfcc0",
"ep": 1,
"script": "xiaomi_rtczcgq11lm_presenceevent.js",
"fn": "zcl"
},
"default": "leave"
}
]
}
]
}
32 changes: 32 additions & 0 deletions devices/xiaomi/xiaomi_rtczcgq11lm_presenceevent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
switch (Attr.val) {
case 0:
Item.val = "enter";
break;
case 1:
Item.val = "leave";
break;
case 2:
Item.val = "enterleft";
break;
case 3:
Item.val = "rightleave";
break;
case 4:
Item.val = "enterright";
break;
case 5:
Item.val = "leftleave";
break;
case 6:
Item.val = "approaching";
break;
case 7:
Item.val = "absenting";
break;
case 8:
Item.val = "8";
break;
case 9:
Item.val = "9";
break;
}
39 changes: 38 additions & 1 deletion general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4259,7 +4259,7 @@ Contactor > On/off=0003 - HP/HC=0004</description>
</attribute>
<attribute id="0x0112" name="Unknown" type="u32" mfcode="0x115f" access="r" required="m"> </attribute>
<attribute id="0x0114" name="TVOC unit config" type="u8" mfcode="0x115f" access="rw" required="m">
<description>0 - µg/m³ + °C, 1 - µg/m³ + °F, 16 - ppb + °C, 17 - ppb + °F</description>
<description>0 - µg/m³ + °C, 1 - ppb + °C, 16 - µg/m³ + °F, 17 - ppb + °F</description>
</attribute>
<attribute id="0x0125" name="Multiclick mode" type="u8" mfcode="0x115f" access="rw" required="m"> </attribute>
<attribute id="0x0135" name="Unknown" type="u8" mfcode="0x115f" access="rw" required="m"> </attribute>
Expand Down Expand Up @@ -4329,6 +4329,43 @@ Contactor > On/off=0003 - HP/HC=0004</description>
</client>
</cluster>

<!-- AQARA -->
<cluster id="0xfcc0" name="Aqara specific" mfcode="0x1234">
<description>Aqara specific attributes.</description>
<server>
<attribute-set id="0x0000" description="Unknown">
<attribute id="0x0006" name="Unknown" type="ostring" access="rw" required="m"> </attribute>
<attribute id="0x0007" name="Unknown" type="ostring" access="rw" required="m"> </attribute>
<attribute id="0x00E4" name="Unknown" type="u32" access="rw" required="m"> </attribute>
<attribute id="0x00F7" name="Unknown" type="ostring" access="r" required="m"> </attribute>
<attribute id="0x00FA" name="Unknown" type="bool" access="rw" required="m"> </attribute>
<attribute id="0x00FC" name="Unknown" type="bool" access="rw" required="m"> </attribute>
<attribute id="0x00FE" name="Serial Number" type="cstring" access="rw" required="m"> </attribute>
<attribute id="0x00FF" name="Unknown" type="ostring" access="rw" required="m"> </attribute>
<attribute id="0x010C" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0133" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0134" name="Unknown" type="ostring" access="rw" required="m"> </attribute>
<attribute id="0x0142" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0143" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0144" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0145" name="Unknown" type="bool" access="rw" required="m"> </attribute>
<attribute id="0x0146" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0147" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0148" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0149" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0150" name="Unknown" type="ostring" access="rw" required="m"> </attribute>
<attribute id="0x0151" name="Unknown" type="ostring" access="rw" required="m"> </attribute>
<attribute id="0x0153" name="Unknown" type="u32" access="rw" required="m"> </attribute>
<attribute id="0x0154" name="Unknown" type="u32" access="rw" required="m"> </attribute>
<attribute id="0x0155" name="Unknown" type="u8" access="rw" required="m"> </attribute>
<attribute id="0x0156" name="Unknown" type="u32" access="rw" required="m"> </attribute>
<attribute id="0x0157" name="Unknown" type="u8" access="w" required="m"> </attribute>
</attribute-set>
</server>
<client>
</client>
</cluster>

<!-- SINOPE -->
<cluster id="0xff01" name="Sinope specific" mfcode="0x119c">
<description>Sinope specific attributes.
Expand Down
4 changes: 4 additions & 0 deletions resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const char *RStateOrientationY = "state/orientation_y";
const char *RStateOrientationZ = "state/orientation_z";
const char *RStatePanel = "state/panel";
const char *RStatePresence = "state/presence";
const char *RStatePresenceEvent = "state/presenceevent";
const char *RStatePressure = "state/pressure";
const char *RStateMoisture = "state/moisture";
const char *RStatePower = "state/power";
Expand Down Expand Up @@ -227,6 +228,7 @@ const char *RConfigTempMinThreshold = "config/temperatureminthreshold";
const char *RConfigHumiMaxThreshold = "config/humiditymaxthreshold";
const char *RConfigHumiMinThreshold = "config/humidityminthreshold";
const char *RConfigReachable = "config/reachable";
const char *RConfigResetPresence = "config/resetpresence";
const char *RConfigSchedule = "config/schedule";
const char *RConfigScheduleOn = "config/schedule_on";
const char *RConfigSensitivity = "config/sensitivity";
Expand Down Expand Up @@ -353,6 +355,7 @@ void initResourceDescriptors()
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeInt16, QVariant::Double, RStateOrientationZ));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeString, QVariant::String, RStatePanel));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeBool, QVariant::Bool, RStatePresence));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeString, QVariant::String, RStatePresenceEvent));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeInt16, QVariant::Double, RStatePressure, 0, 32767));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeInt16, QVariant::Double, RStateMoisture));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeInt16, QVariant::Double, RStatePower));
Expand Down Expand Up @@ -446,6 +449,7 @@ void initResourceDescriptors()
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeInt8, QVariant::Double, RConfigHumiMaxThreshold));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeInt8, QVariant::Double, RConfigHumiMinThreshold));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeBool, QVariant::Bool, RConfigReachable));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeBool, QVariant::Bool, RConfigResetPresence));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeString, QVariant::String, RConfigSchedule));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeBool, QVariant::Bool, RConfigScheduleOn));
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeUInt8, QVariant::Double, RConfigSensitivity));
Expand Down
2 changes: 2 additions & 0 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ extern const char *RStateOrientationY;
extern const char *RStateOrientationZ;
extern const char *RStatePanel;
extern const char *RStatePresence;
extern const char *RStatePresenceEvent;
extern const char *RStatePressure;
extern const char *RStateMoisture;
extern const char *RStatePower;
Expand Down Expand Up @@ -247,6 +248,7 @@ extern const char *RConfigHumiMaxThreshold;
extern const char *RConfigHumiMinThreshold;
extern const char *RConfigVolume;
extern const char *RConfigReachable;
extern const char *RConfigResetPresence;
extern const char *RConfigSchedule;
extern const char *RConfigScheduleOn;
extern const char *RConfigSensitivity;
Expand Down
29 changes: 25 additions & 4 deletions rest_sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,22 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
}
else if (rid.suffix == RConfigSensitivity) // Unsigned integer
{
pendingMask |= R_PENDING_SENSITIVITY;
sensor->enableRead(WRITE_SENSITIVITY);
sensor->setNextReadTime(WRITE_SENSITIVITY, QTime::currentTime());
updated = true;
if (!devManaged)
{
pendingMask |= R_PENDING_SENSITIVITY;
sensor->enableRead(WRITE_SENSITIVITY);
sensor->setNextReadTime(WRITE_SENSITIVITY, QTime::currentTime());
updated = true;
}
else
{
if (rsub)
{
change.addTargetValue(rid.suffix, data.uinteger);
rsub->addStateChange(change);
updated = true;
}
}
}
else if (rid.suffix == RConfigUsertest) // Boolean
{
Expand All @@ -895,6 +907,15 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
{
updated = true;
}
else if (rid.suffix == RConfigResetPresence) // Boolean
{
if (devManaged && rsub)
{
change.addTargetValue(rid.suffix, data.boolean);
rsub->addStateChange(change);
updated = true;
}
}
else if (rid.suffix == RConfigAlert) // String
{
const std::array<KeyValMap, 3> RConfigAlertValues = { { {QLatin1String("none"), 0}, {QLatin1String("select"), 2}, {QLatin1String("lselect"), 15} } };
Expand Down

0 comments on commit a532f0f

Please sign in to comment.