Skip to content

Commit

Permalink
Rules are working
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 24, 2024
1 parent 3c7f89d commit 0444f90
Show file tree
Hide file tree
Showing 35 changed files with 4,427 additions and 4,330 deletions.
11 changes: 9 additions & 2 deletions build-backend/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build-backend/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src-editor/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ class App extends GenericApp<AppProps, AppState> {

onEnableDisable(id: string, enabled: boolean): void {
if (this.scripts[id] && this.scripts[id].type === 'script') {
const common = this.scripts[id].common;
const common: ioBroker.ScriptCommon = this.scripts[id].common as ioBroker.ScriptCommon;
common.enabled = enabled;
common.expert = true;
this.updateScript(id, id, common).catch(err => err !== 'canceled' && this.showJsError(err));
Expand Down
8 changes: 4 additions & 4 deletions src-editor/src/Components/BlocklyEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ class BlocklyEditor extends React.Component<BlocklyEditorProps, BlocklyEditorSta
const selectedBlocks: BlocklyTS.BlockSvg | null = BlocklyTS.getSelected() as BlocklyTS.BlockSvg | null;
if (selectedBlocks) {
const xmlBlock: Element = BlocklyTS.Xml.blockToDom(selectedBlocks) as Element;
// @ts-expect-error fix later
if (BlocklyTS.dragMode_ !== BlocklyTS.DRAG_FREE) {
BlocklyTS.Xml.deleteNext(xmlBlock);
}
// @1ts-expect-error fix later. TODO!!!!
// if (BlocklyTS.dragMode_ !== BlocklyTS.DRAG_FREE) {
// BlocklyTS.Xml.deleteNext(xmlBlock);
// }
// Encode start position in XML.
const xy = selectedBlocks.getRelativeToSurfaceXY();
xmlBlock.setAttribute('x', (selectedBlocks.RTL ? -xy.x : xy.x).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ActionOperateStates extends GenericBlock<RuleBlockConfigActionOperationSta

isAllTriggersOnState(): boolean {
return (
this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!!this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!this.props.userRules?.triggers?.find(item => item.id !== 'TriggerState')
);
}
Expand All @@ -38,7 +38,9 @@ class ActionOperateStates extends GenericBlock<RuleBlockConfigActionOperationSta
return (
<span>
{I18n.t('Set:')}{' '}
<span className={debugMessage.data.ack ? this.props.classes.valueAck : this.props.classes.valueNotAck}>
<span
className={debugMessage.data.ack ? this.props.classes?.valueAck : this.props.classes?.valueNotAck}
>
{renderValue(debugMessage.data.val)}
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ActionSetState extends GenericBlock<RuleBlockConfigActionSetState> {

isAllTriggersOnState(): boolean {
return (
this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!!this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!this.props.userRules?.triggers?.find(item => item.id !== 'TriggerState')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActionSetStateDelayed extends GenericBlock<RuleBlockConfigActionSetStateDe

isAllTriggersOnState(): boolean {
return (
this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!!this.props.userRules?.triggers?.find(item => item.id === 'TriggerState') &&
!this.props.userRules?.triggers?.find(item => item.id !== 'TriggerState')
);
}
Expand Down Expand Up @@ -60,7 +60,9 @@ class ActionSetStateDelayed extends GenericBlock<RuleBlockConfigActionSetStateDe
return (
<span>
{I18n.t('Set:')}{' '}
<span className={debugMessage.data.ack ? this.props.classes.valueAck : this.props.classes.valueNotAck}>
<span
className={debugMessage.data.ack ? this.props.classes?.valueAck : this.props.classes?.valueNotAck}
>
{renderValue(debugMessage.data.val)}
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GenericBlock, type GenericBlockProps, type GenericBlockState } from '..
import HysteresisImage from '../../../assets/hysteresis.png';
import type {
RuleBlockConfigActionActionState,
RuleBlockConfigTriggerState,
RuleBlockDescription,
RuleContext,
RuleInputAny,
Expand Down Expand Up @@ -97,7 +98,7 @@ class ConditionState extends GenericBlock<RuleBlockConfigActionActionState, Cond
const compare = config.tagCard === '=' ? '==' : config.tagCard === '<>' ? '!=' : config.tagCard;
if (config.useTrigger) {
debugValue = 'obj.state.val';
if (context?.trigger?.oidType === 'string') {
if ((context?.trigger as RuleBlockConfigTriggerState)?.oidType === 'string') {
value = (value as string).replace(/"/g, '\\"');
result = `subCondVar${config._id} ${compare} "${value}"`;
} else {
Expand Down Expand Up @@ -127,7 +128,7 @@ class ConditionState extends GenericBlock<RuleBlockConfigActionActionState, Cond
} else {
if (config.useTrigger) {
debugValue = 'obj.state.val';
if (context?.trigger?.oidType === 'string') {
if ((context?.trigger as RuleBlockConfigTriggerState)?.oidType === 'string') {
value = (value as string).replace(/"/g, '\\"');
result = `obj.state.val.includes("${value}")`;
} else {
Expand Down Expand Up @@ -183,9 +184,9 @@ class ConditionState extends GenericBlock<RuleBlockConfigActionActionState, Cond
}

if (isAllTriggersOnState && useTrigger && this.props.userRules?.triggers?.length === 1) {
oidType = this.props.userRules.triggers[0].oidType;
oidUnit = this.props.userRules.triggers[0].oidUnit;
oidStates = this.props.userRules.triggers[0].oidStates;
oidType = (this.props.userRules.triggers[0] as RuleBlockConfigTriggerState).oidType;
oidUnit = (this.props.userRules.triggers[0] as RuleBlockConfigTriggerState).oidUnit;
oidStates = (this.props.userRules.triggers[0] as RuleBlockConfigTriggerState).oidStates;
}

const _tagCardArray: RuleTagCard[] = ConditionState.getStaticData().tagCardArray as RuleTagCard[];
Expand Down Expand Up @@ -233,7 +234,14 @@ class ConditionState extends GenericBlock<RuleBlockConfigActionActionState, Cond
];

if (oidStates) {
options = Object.keys(oidStates).map(val => ({ value: val, title: oidStates[val] }));
options = Object.keys(oidStates)
.map(val => {
if (oidStates) {
return { value: val, title: oidStates[val] };
}
return null;
})
.filter(i => i) as { value: string | boolean; title: string }[];
}
} else if (oidType === 'boolean') {
tagCardArray = [
Expand Down Expand Up @@ -291,7 +299,10 @@ class ConditionState extends GenericBlock<RuleBlockConfigActionActionState, Cond
},
];
if (oidStates) {
options = Object.keys(oidStates).map(val => ({ value: val, title: oidStates[val] }));
options = Object.keys(oidStates).map(val => ({
value: val,
title: oidStates ? oidStates[val] : val.toString(),
}));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ComplexCron, Schedule, I18n } from '@iobroker/adapter-react-v5';
import convertCronToText from '@iobroker/adapter-react-v5/build/Components/SimpleCron/cronText';

import { GenericBlock, type GenericBlockProps, type GenericBlockState } from '../GenericBlock';
import Compile from '../../helpers/Compile';
import { STANDARD_FUNCTION_STATE, STANDARD_FUNCTION_STATE_ONCHANGE } from '../../helpers/Compile';
import CustomInput from '../CustomInput';
import CustomButton from '../CustomButton';
import CustomModal from '../CustomModal';
Expand Down Expand Up @@ -63,7 +63,7 @@ class TriggerScheduleBlock extends GenericBlock<RuleBlockConfigTriggerSchedule,

static compile(config: RuleBlockConfigTriggerSchedule, context: RuleContext): string {
let text = '';
let func = context.justCheck ? Compile.STANDARD_FUNCTION_STATE : Compile.STANDARD_FUNCTION_STATE_ONCHANGE;
let func = context.justCheck ? STANDARD_FUNCTION_STATE : STANDARD_FUNCTION_STATE_ONCHANGE;
func = func.replace('"__%%DEBUG_TRIGGER%%__"', `_sendToFrontEnd(${config._id}, {trigger: true})`);

if (config.tagCard === 'interval') {
Expand Down Expand Up @@ -214,7 +214,7 @@ class TriggerScheduleBlock extends GenericBlock<RuleBlockConfigTriggerSchedule,
},
{
nameRender: 'renderNameText',
attr: 'textTime',
attr: 'textTime1',
defaultValue: time,
},
];
Expand Down Expand Up @@ -317,24 +317,25 @@ class TriggerScheduleBlock extends GenericBlock<RuleBlockConfigTriggerSchedule,
onClick={() => this.setState({ openDialog: true })}
/>
</div>
<CustomModal
open={!!this.state.openDialog}
onApply={(): void => {
onChange(textCron, attr, () => {
onChange(convertCronToText(textCron, I18n.getLanguage()), 'addText');
this.setState({ openDialog: false });
});
}}
onClose={() => this.setState({ openDialog: false })}
>
<ComplexCron
cronExpression={
(settings as Record<string, any>)[attr] ? (settings as Record<string, any>)[attr] : ''
}
onChange={el => (textCron = el)}
language={I18n.getLanguage()}
/>
</CustomModal>
{this.state.openDialog ? (
<CustomModal
onApply={(): void => {
onChange(textCron, attr, () => {
onChange(convertCronToText(textCron, I18n.getLanguage()), 'addText');
this.setState({ openDialog: false });
});
}}
onClose={() => this.setState({ openDialog: false })}
>
<ComplexCron
cronExpression={
(settings as Record<string, any>)[attr] ? (settings as Record<string, any>)[attr] : ''
}
onChange={el => (textCron = el)}
language={I18n.getLanguage()}
/>
</CustomModal>
) : null}
{this.renderNameText(
{
nameRender: 'renderNameText',
Expand Down Expand Up @@ -383,30 +384,31 @@ class TriggerScheduleBlock extends GenericBlock<RuleBlockConfigTriggerSchedule,
onClick={() => this.setState({ openDialog: true })}
/>
</div>
<CustomModal
open={!!this.state.openDialog}
onApply={() =>
this.setState({ openDialog: false }, () =>
onChange({
[`${attr}Text`]: wizardText,
[attr]: wizard,
}),
)
}
onClose={() => this.setState({ openDialog: false })}
>
<Schedule
theme={this.props.theme}
schedule={value}
onChange={(schedule, description) => {
wizardText = description || '';
const wizardObj: ScheduleConfig = JSON.parse(schedule) as ScheduleConfig;
wizardObj.valid = wizardObj.valid || {};
wizardObj.valid.from = wizardObj.valid.from || Schedule.now2string();
wizard = JSON.stringify(wizardObj);
}}
/>
</CustomModal>
{this.state.openDialog ? (
<CustomModal
onApply={() =>
this.setState({ openDialog: false }, () =>
onChange({
[`${attr}Text`]: wizardText,
[attr]: wizard,
}),
)
}
onClose={() => this.setState({ openDialog: false })}
>
<Schedule
theme={this.props.theme}
schedule={value}
onChange={(schedule, description) => {
wizardText = description || '';
const wizardObj: ScheduleConfig = JSON.parse(schedule) as ScheduleConfig;
wizardObj.valid = wizardObj.valid || {};
wizardObj.valid.from = wizardObj.valid.from || Schedule.now2string();
wizard = JSON.stringify(wizardObj);
}}
/>
</CustomModal>
) : null}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { I18n } from '@iobroker/adapter-react-v5';
import { GenericBlock, type GenericBlockProps } from '../GenericBlock';
import Compile from '../../helpers/Compile';
import { NO_FUNCTION } from '../../helpers/Compile';
import type {
RuleBlockConfigTriggerScriptSave,
RuleBlockDescription,
Expand All @@ -14,10 +14,7 @@ class TriggerScriptSave extends GenericBlock<RuleBlockConfigTriggerScriptSave> {
}

static compile(config: RuleBlockConfigTriggerScriptSave, _context: RuleContext): string {
return Compile.NO_FUNCTION.replace(
'"__%%DEBUG_TRIGGER%%__"',
`_sendToFrontEnd(${config._id}, {trigger: true})`,
);
return NO_FUNCTION.replace('"__%%DEBUG_TRIGGER%%__"', `_sendToFrontEnd(${config._id}, {trigger: true})`);
}

// eslint-disable-next-line class-methods-use-this
Expand Down
Loading

0 comments on commit 0444f90

Please sign in to comment.