Skip to content

Commit

Permalink
feat(epl): add max_distance setting
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBol committed Feb 16, 2024
1 parent 0ff7849 commit 40b626c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
25 changes: 25 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,31 @@
}
}
]
},
{
"type": "group",
"label": {
"en": "mmWave"
},
"children": [
{
"id": "max_distance",
"type": "number",
"label": {
"en": "mmWave distance"
},
"value": 600,
"min": 0,
"max": 600,
"step": 1,
"units": {
"en": "cm"
},
"hint": {
"en": "Configure the distance of the room the sensor is placed in. This is important for accurate mmWave occupancy detection. See the Everything Presence Lite documentation for more information."
}
}
]
}
]
},
Expand Down
17 changes: 16 additions & 1 deletion drivers/everything-presence-lite/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ const CONNECT_TIMEOUT = 15000;
// } +1ms

enum DRIVER_SETTINGS {
ESP_32_LED = 'esp32_led'
ESP_32_LED = 'esp32_led',
MMWAVE_DISTANCE = 'max_distance' // Why is this id max_distance and not distance?
}

const entityStateSchema = z.object({
Expand Down Expand Up @@ -486,6 +487,19 @@ class EverythingPresenceLiteDevice extends Homey.Device {

// Read and update settings
switch (entity.config.objectId) {
case DRIVER_SETTINGS.MMWAVE_DISTANCE:
// Throw when state is not a number
z.number().parse(parsedState.state);
this.debugEntity(`Setting: ${entity.config.objectId}: state event`, parsedState.state);
this.setSettings({
[entity.config.objectId]: parsedState.state
}).catch((err) =>
this.debugEntity(
`Failed to set setting ${entity.config.objectId} to value: ${parsedState.state}, reason:`,
err
)
);
break;
case DRIVER_SETTINGS.ESP_32_LED:
// Throw when state is not a boolean
z.boolean().parse(parsedState.state);
Expand Down Expand Up @@ -529,6 +543,7 @@ class EverythingPresenceLiteDevice extends Homey.Device {
this.log('EverythingPresenceLiteDevice settings were changed');
for (const changedKey of changedKeys) {
switch (changedKey) {
case DRIVER_SETTINGS.MMWAVE_DISTANCE:
case DRIVER_SETTINGS.ESP_32_LED:
const entity = this.entities.get(changedKey);
if (!entity) throw new Error(`Missing entity ${changedKey}`);
Expand Down
19 changes: 19 additions & 0 deletions drivers/everything-presence-lite/driver.settings.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,24 @@
"hint": { "en": "Enable or disable the ESP32 status LED." }
}
]
},
{
"type": "group",
"label": { "en": "mmWave" },
"children": [
{
"id": "max_distance",
"type": "number",
"label": { "en": "mmWave distance" },
"value": 600,
"min": 0,
"max": 600,
"step": 1,
"units": { "en": "cm" },
"hint": {
"en": "Configure the distance of the room the sensor is placed in. This is important for accurate mmWave occupancy detection. See the Everything Presence Lite documentation for more information."
}
}
]
}
]

0 comments on commit 40b626c

Please sign in to comment.