Skip to content

Commit

Permalink
Add a reaction to lost roller shutter calibration
Browse files Browse the repository at this point in the history
fix #866
  • Loading branch information
fracz committed Sep 19, 2024
1 parent c4d8535 commit b30fdd3
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
62 changes: 60 additions & 2 deletions src/SuplaBundle/Model/ValueBasedTriggerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,57 @@ class ValueBasedTriggerValidator {
ChannelFunction::IC_GASMETER,
ChannelFunction::IC_ELECTRICITYMETER,
],
'default' => [ChannelFunction::VALVEOPENCLOSE],
'calibration_failed' => [
ChannelFunction::CONTROLLINGTHEROLLERSHUTTER,
ChannelFunction::CONTROLLINGTHEROOFWINDOW,
ChannelFunction::CONTROLLINGTHEFACADEBLIND,
ChannelFunction::TERRACE_AWNING,
ChannelFunction::PROJECTOR_SCREEN,
ChannelFunction::CURTAIN,
ChannelFunction::ROLLER_GARAGE_DOOR,
ChannelFunction::VERTICAL_BLIND,
],
'calibration_in_progress' => [
ChannelFunction::CONTROLLINGTHEROLLERSHUTTER,
ChannelFunction::CONTROLLINGTHEROOFWINDOW,
ChannelFunction::CONTROLLINGTHEFACADEBLIND,
ChannelFunction::TERRACE_AWNING,
ChannelFunction::PROJECTOR_SCREEN,
ChannelFunction::CURTAIN,
ChannelFunction::ROLLER_GARAGE_DOOR,
ChannelFunction::VERTICAL_BLIND,
],
'calibration_lost' => [
ChannelFunction::CONTROLLINGTHEROLLERSHUTTER,
ChannelFunction::CONTROLLINGTHEROOFWINDOW,
ChannelFunction::CONTROLLINGTHEFACADEBLIND,
ChannelFunction::TERRACE_AWNING,
ChannelFunction::PROJECTOR_SCREEN,
ChannelFunction::CURTAIN,
ChannelFunction::ROLLER_GARAGE_DOOR,
ChannelFunction::VERTICAL_BLIND,
],
'motor_problem' => [
ChannelFunction::CONTROLLINGTHEROLLERSHUTTER,
ChannelFunction::CONTROLLINGTHEROOFWINDOW,
ChannelFunction::CONTROLLINGTHEFACADEBLIND,
ChannelFunction::TERRACE_AWNING,
ChannelFunction::PROJECTOR_SCREEN,
ChannelFunction::CURTAIN,
ChannelFunction::ROLLER_GARAGE_DOOR,
ChannelFunction::VERTICAL_BLIND,
],
'default' => [
ChannelFunction::VALVEOPENCLOSE,
ChannelFunction::CONTROLLINGTHEROLLERSHUTTER,
ChannelFunction::CONTROLLINGTHEROOFWINDOW,
ChannelFunction::CONTROLLINGTHEFACADEBLIND,
ChannelFunction::TERRACE_AWNING,
ChannelFunction::PROJECTOR_SCREEN,
ChannelFunction::CURTAIN,
ChannelFunction::ROLLER_GARAGE_DOOR,
ChannelFunction::VERTICAL_BLIND,
],
];

private const THRESHOLD_SUPPORT = [
Expand Down Expand Up @@ -153,6 +203,13 @@ class ValueBasedTriggerValidator {
ChannelFunction::GENERAL_PURPOSE_MEASUREMENT,
];

const BOOLEAN_FIELD_NAMES = [
'calibration_failed',
'calibration_in_progress',
'calibration_lost',
'motor_problem',
];

/**
* @OA\Schema(schema="ReactionTriggerChange", description="Reaction trigger based any state (on every change).",
* @OA\Property(property="on_change", type="object",
Expand Down Expand Up @@ -284,7 +341,8 @@ private function validateEqualityTrigger(IODeviceChannel $channel, array $onChan
$mainCondition = array_intersect_key($onChangeTo, array_flip(['eq', 'ne']));
Assertion::count($mainCondition, 1, 'You must define only one condition for the threshold (eq, ne).');
$operator = key($mainCondition);
if (in_array($channel->getFunction()->getId(), self::THRESHOLD_SUPPORT)) {
$fieldName = $onChangeTo['name'] ?? 'default';
if (in_array($channel->getFunction()->getId(), self::THRESHOLD_SUPPORT) && !in_array($fieldName, self::BOOLEAN_FIELD_NAMES)) {
Assertion::numeric($onChangeTo[$operator], 'Threshold must be numeric.');
} else {
Assertion::inArray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function validTriggers() {
[ChannelFunction::GENERAL_PURPOSE_MEASUREMENT(), '{"on_change_to": {"gt": 20}}'],
[ChannelFunction::GENERAL_PURPOSE_MEASUREMENT(), '{"on_change_to": {"gt": 20, "resume": {"le": 10}}}'],
[ChannelFunction::GENERAL_PURPOSE_MEASUREMENT(), '{"on_change": {}}'],
[ChannelFunction::CONTROLLINGTHEROLLERSHUTTER(), '{"on_change": {}}'],
[ChannelFunction::CONTROLLINGTHEROLLERSHUTTER(), '{"on_change_to": {"ge": 20, "resume": {"lt": 10}}}'],
[ChannelFunction::CONTROLLINGTHEROLLERSHUTTER(), '{"on_change_to": {"eq": "on", "name": "calibration_failed"}}'],
[ChannelFunction::CONTROLLINGTHEROLLERSHUTTER(), '{"on_change_to": {"eq": "on", "name": "motor_problem"}}'],
];
}

Expand Down
26 changes: 25 additions & 1 deletion src/frontend/src/channels/reactions/channel-function-triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const ChannelFunctionTriggers = {
[ChannelFunction.CONTROLLINGTHEROLLERSHUTTER]: [
{
caption: () => 'When the roller shutter reaches a certain position', // i18n
test: (t) => !!t.on_change_to,
test: (t) => !!t.on_change_to && !t.on_change_to.name,
component: ReactionConditionThreshold,
props: {
min: () => 0, max: () => 100, step: () => 1,
Expand All @@ -91,6 +91,30 @@ export const ChannelFunctionTriggers = {
resumeLabelI18n: () => 'and wait until it reaches', // i18n
},
},
{
caption: () => 'When the roller shutter calibration failed', // i18n
test: (t) => t.on_change_to?.name === 'calibration_failed',
def: () => ({on_change_to: {eq: 'on', name: 'calibration_failed'}}),
canBeSetForChannel: (channel) => channel.config.autoCalibrationAvailable,
},
{
caption: () => 'When the roller shutter calibration has started', // i18n
test: (t) => t.on_change_to?.name === 'calibration_in_progress',
def: () => ({on_change_to: {eq: 'on', name: 'calibration_in_progress'}}),
canBeSetForChannel: (channel) => channel.config.autoCalibrationAvailable,
},
{
caption: () => 'When the roller shutter calibration has been lost', // i18n
test: (t) => t.on_change_to?.name === 'calibration_lost',
def: () => ({on_change_to: {eq: 'on', name: 'calibration_lost'}}),
canBeSetForChannel: (channel) => channel.config.autoCalibrationAvailable,
},
{
caption: () => 'When the roller shutter motor reported a problem', // i18n
test: (t) => t.on_change_to?.name === 'motor_problem',
def: () => ({on_change_to: {eq: 'on', name: 'motor_problem'}}),
canBeSetForChannel: (channel) => channel.config.autoCalibrationAvailable,
},
{
caption: () => 'When the roller shutter position changes', // i18n
def: () => ({on_change: {}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
}
},
possibleConditions() {
return ChannelFunctionTriggers[this.subject.functionId] || [];
return (ChannelFunctionTriggers[this.subject.functionId] || [])
.filter((trigger) => !trigger.canBeSetForChannel || trigger.canBeSetForChannel(this.subject));
}
},
watch: {
Expand Down

0 comments on commit b30fdd3

Please sign in to comment.