latest work
This commit is contained in:
commit
5f486a5f89
37 files changed
+12606
No files matched your search
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"parcel": "^2.0.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-router-dom": "^5.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@parcel/transformer-sass": "^2.0.0",
|
||||
"@parcel/transformer-yaml": "^2.0.0",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/react": "^17.0.33",
|
||||
"@types/react-dom": "^17.0.10",
|
||||
"@types/react-router-dom": "^5.3.2",
|
||||
"concurrently": "^6.3.0",
|
||||
"husky": "^7.0.4",
|
||||
"jest": "^27.3.1",
|
||||
"jest-dom": "^4.0.0",
|
||||
"jest-extended": "^1.1.0",
|
||||
"prettier": "^2.4.1",
|
||||
"react-test-renderer": "^17.0.2",
|
||||
"react-testing-library": "^8.0.1",
|
||||
"ts-jest": "^27.0.7",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-react": "^5.0.0",
|
||||
"typescript": "^4.4.4"
|
||||
},
|
||||
"scripts": {
|
||||
"develop": "concurrently -r \"npm:type-check:watch\" \"npm:start\"",
|
||||
"start": "parcel ./src/index.html",
|
||||
"build": "npm run type-check && parcel build ./src/index.html --public-url '/'",
|
||||
"prettify": "prettier --write './src/**/*.{ts,tsx}'",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"type-check": "tsc --noEmit",
|
||||
"type-check:watch": "tsc --noEmit --watch"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"moduleFileExtensions": [
|
||||
"ts",
|
||||
"tsx",
|
||||
"js"
|
||||
],
|
||||
"setupFilesAfterEnv": [
|
||||
"<rootDir>/src/setupTests.ts"
|
||||
],
|
||||
"moduleNameMapper": {
|
||||
".+\\.css$": "<rootDir>/src/styleMock.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useState } from "react";
|
||||
|
||||
|
||||
|
||||
export abstract class BaseStateManager<T> {
|
||||
abstract defaultState(): T ;
|
||||
abstract isReady(): boolean;
|
||||
abstract renderOptionList(): JSX.Element;
|
||||
|
||||
public state: T;
|
||||
public setState: (s:T) => void;
|
||||
|
||||
constructor(){
|
||||
[this.state, this.setState] = useState(this.defaultState());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { ServiceScript } from "../types/script";
|
||||
import { BaseStateManager } from "./BaseManager";
|
||||
|
||||
|
||||
export class ScriptCallService extends BaseStateManager<ServiceScript> {
|
||||
defaultState(): ServiceScript {
|
||||
return {
|
||||
service: "",
|
||||
alias: "Call Service",
|
||||
target: "",
|
||||
data: {},
|
||||
}
|
||||
}
|
||||
isReady(): boolean {
|
||||
return this.state.service !== '' &&
|
||||
this.state.alias !== '' &&
|
||||
this.state.target !== ''
|
||||
}
|
||||
renderOptionList(): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<label htmlFor="#alias">Description</label>
|
||||
<input id="alias" value={this.state.alias} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...this.state,
|
||||
alias: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
<label htmlFor="#service">Service</label>
|
||||
<input id="service" value={this.state.service} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...this.state,
|
||||
service: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
<label htmlFor="#target">Target</label>
|
||||
<input id="target" value={this.state.target} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...this.state,
|
||||
target: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export interface AutomationTime {
|
||||
hours?: number;
|
||||
minutes?: number;
|
||||
seconds?: number;
|
||||
milliseconds?: number;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { AutomationTime } from "./common";
|
||||
|
||||
interface BaseCondition {
|
||||
alias: string;
|
||||
};
|
||||
export interface LogicCondition extends BaseCondition {
|
||||
condition: 'and' | 'or' | 'not';
|
||||
conditions: AutomationCondition[];
|
||||
}
|
||||
export interface NumericCondition extends BaseCondition {
|
||||
condition: 'numeric_state';
|
||||
entity_id: string;
|
||||
above?: string;
|
||||
below?: string;
|
||||
attribute?: string;
|
||||
value_template?: string;
|
||||
}
|
||||
export interface StateCondition extends BaseCondition {
|
||||
condition: 'state';
|
||||
entity_id: string | string[];
|
||||
state: string | string[];
|
||||
for?: AutomationTime | string;
|
||||
attribute?: string;
|
||||
}
|
||||
export interface TemplateCondition extends BaseCondition {
|
||||
condition: 'template';
|
||||
value_template: string;
|
||||
}
|
||||
export interface TimeCondition extends BaseCondition {
|
||||
condition: 'time';
|
||||
after?: string;
|
||||
before?: string;
|
||||
weekday?: Array<'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun'>;
|
||||
}
|
||||
export interface TriggerCondition extends BaseCondition {
|
||||
condition: 'trigger';
|
||||
id: string | string[];
|
||||
}
|
||||
export interface ZoneCondition extends BaseCondition {
|
||||
condition: 'zone';
|
||||
zone: string;
|
||||
entity_id: string | string[];
|
||||
state: string | string[];
|
||||
}
|
||||
export interface GenericCondition extends BaseCondition {
|
||||
condition: string;
|
||||
}
|
||||
export type AutomationCondition =
|
||||
| string // <-- this is the same as "TemplateCondition"
|
||||
| LogicCondition
|
||||
| NumericCondition
|
||||
| StateCondition
|
||||
| TemplateCondition
|
||||
| TimeCondition
|
||||
| TriggerCondition
|
||||
| ZoneCondition
|
||||
| GenericCondition
|
||||
;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { AutomationCondition } from "./condition";
|
||||
import { AutomationScript } from "./script";
|
||||
import { AutomationTrigger } from "./triggers";
|
||||
|
||||
export interface Automation {
|
||||
id: string;
|
||||
alias: string;
|
||||
description: string;
|
||||
trigger_variables: Record<string, string>;
|
||||
mode: "single" | "restart" | "queued" | "parallel";
|
||||
trigger: AutomationTrigger[];
|
||||
condition: AutomationCondition[];
|
||||
action: AutomationAction[];
|
||||
}
|
||||
|
||||
export type AutomationNodeTypes = Pick<Automation, 'trigger' | 'condition' | 'action'>;
|
||||
export type AutomationNodeType = keyof AutomationNodeTypes;
|
||||
export type AutomationAction = AutomationScript | AutomationCondition;
|
||||
export type AutomationNode<T extends AutomationNodeType> =
|
||||
AutomationNodeTypes[T][number];
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { AutomationCondition } from "./condition";
|
||||
|
||||
interface BaseScript {
|
||||
alias: string;
|
||||
variables?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface ServiceScript extends BaseScript {
|
||||
service: string;
|
||||
target: any;
|
||||
data: any;
|
||||
}
|
||||
export interface RepeatScript extends BaseScript {
|
||||
repeat: {
|
||||
count: number;
|
||||
sequence: AutomationScript[];
|
||||
}
|
||||
}
|
||||
export interface WaitScript extends BaseScript {
|
||||
wait_template: string;
|
||||
timeout?: number;
|
||||
continue_on_timeout?: boolean;
|
||||
}
|
||||
export interface FireEventScript extends BaseScript {
|
||||
event: string;
|
||||
event_data: any;
|
||||
}
|
||||
export interface DeviceScript extends BaseScript {
|
||||
type: string;
|
||||
device_id: string;
|
||||
entity_id: string;
|
||||
domain: string;
|
||||
}
|
||||
export interface ChooseScript extends BaseScript {
|
||||
choose: Array<{
|
||||
conditions: AutomationCondition[];
|
||||
sequence: AutomationScript[];
|
||||
}>;
|
||||
default: AutomationScript[];
|
||||
}
|
||||
export type AutomationScript =
|
||||
| ServiceScript
|
||||
| RepeatScript
|
||||
| WaitScript
|
||||
| FireEventScript
|
||||
| DeviceScript
|
||||
| ChooseScript
|
||||
;
|
||||
@@ -0,0 +1,90 @@
|
||||
import { AutomationTime } from "./common";
|
||||
|
||||
export interface AutomationTriggerEvent {
|
||||
platform: 'event';
|
||||
event_type: string;
|
||||
event_data?: any;
|
||||
context?: any;
|
||||
}
|
||||
export interface AutomationTriggerHA {
|
||||
platform: 'homeassistant';
|
||||
event: 'start' | 'shutdown';
|
||||
}
|
||||
export interface AutomationTriggerMQTT {
|
||||
platform: 'mqtt';
|
||||
topic: string;
|
||||
payload: string;
|
||||
value_template: string;
|
||||
}
|
||||
export interface AutomationTriggerNumericState {
|
||||
platform: 'numeric_state';
|
||||
entity_id: string | string[];
|
||||
attribute?: string;
|
||||
value_template?: string;
|
||||
above?: string;
|
||||
below?: string;
|
||||
for?: AutomationTime | string;
|
||||
}
|
||||
export interface AutomationTriggerState {
|
||||
platform: 'state';
|
||||
entity_id: string | string[];
|
||||
attribute?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
for?: AutomationTime | string;
|
||||
}
|
||||
export interface AutomationTriggerTag {
|
||||
platform: 'tag';
|
||||
tag_id: string | string[];
|
||||
device_id: string | string[];
|
||||
}
|
||||
export interface AutomationTriggerTemplate {
|
||||
platform: 'template';
|
||||
value_template: string;
|
||||
for?: AutomationTime | string;
|
||||
}
|
||||
export interface AutomationTriggerTime {
|
||||
platform: 'time';
|
||||
at: string | string[];
|
||||
}
|
||||
export interface AutomationTriggerTimePattern {
|
||||
platform: 'time_pattern';
|
||||
hours?: string;
|
||||
minutes?: string;
|
||||
seconds?: string;
|
||||
}
|
||||
export interface AutomationTriggerWebhook {
|
||||
platform: 'webhook';
|
||||
webhook_id: string;
|
||||
}
|
||||
export interface AutomationTriggerZone {
|
||||
platform: 'zone';
|
||||
entity_id: string;
|
||||
zone: string;
|
||||
event: 'enter' | 'leave';
|
||||
}
|
||||
export interface AutomationTriggerDevice {
|
||||
platform: 'device';
|
||||
device_id: string;
|
||||
domain: string;
|
||||
type: string;
|
||||
subtype: string;
|
||||
}
|
||||
export type AutomationTriggerGeneric = {
|
||||
platform: string;
|
||||
}
|
||||
export type AutomationTrigger =
|
||||
| AutomationTriggerEvent
|
||||
| AutomationTriggerHA
|
||||
| AutomationTriggerMQTT
|
||||
| AutomationTriggerNumericState
|
||||
| AutomationTriggerState
|
||||
| AutomationTriggerTag
|
||||
| AutomationTriggerTemplate
|
||||
| AutomationTriggerTime
|
||||
| AutomationTriggerTimePattern
|
||||
| AutomationTriggerWebhook
|
||||
| AutomationTriggerZone
|
||||
| AutomationTriggerDevice
|
||||
| AutomationTriggerGeneric
|
||||
;
|
||||
@@ -0,0 +1,112 @@
|
||||
import { BaseStateManager } from "./StateManager/BaseManager";
|
||||
import { ScriptCallService } from "./StateManager/ScriptService";
|
||||
import { AutomationNode, AutomationNodeType } from "./types";
|
||||
|
||||
export const triggerTypes = [
|
||||
'Event',
|
||||
'Home Assistant',
|
||||
'MQTT',
|
||||
'Numeric State',
|
||||
'State',
|
||||
'Tag',
|
||||
'Template',
|
||||
'Time',
|
||||
'Time Pattern',
|
||||
'Webhook',
|
||||
'Zone',
|
||||
'Device',
|
||||
] as const;
|
||||
export type TriggerType = typeof triggerTypes[number];
|
||||
export const conditionTypes = [
|
||||
'And' ,
|
||||
'Or' ,
|
||||
'Not',
|
||||
'Numeric State',
|
||||
'State',
|
||||
'Template',
|
||||
'Time',
|
||||
'Trigger',
|
||||
'Zone',
|
||||
] as const;
|
||||
export type ConditionType = typeof conditionTypes[number];
|
||||
export const scriptTypes = [
|
||||
'Service',
|
||||
'Repeat',
|
||||
'Wait',
|
||||
'Event',
|
||||
'Device',
|
||||
'Choose'
|
||||
] as const;
|
||||
export type ScriptType = typeof scriptTypes[number];
|
||||
export type NodeStateType<T> =
|
||||
T extends 'action' ? ScriptType :
|
||||
T extends 'condition' ? ConditionType :
|
||||
T extends 'trigger' ? TriggerType :
|
||||
never;
|
||||
|
||||
export const typeList = {
|
||||
'action': scriptTypes,
|
||||
'condition': conditionTypes,
|
||||
'trigger': triggerTypes,
|
||||
} as const;
|
||||
|
||||
export const useNewNodeState = <T extends AutomationNodeType>(
|
||||
node_type: T,
|
||||
node_subtype: NodeStateType<T>
|
||||
) : BaseStateManager<AutomationNode<T>> => {
|
||||
if ( node_type === 'action') {
|
||||
switch (node_subtype) {
|
||||
case 'Service':
|
||||
return new ScriptCallService() as any;
|
||||
// case 'Repeat':
|
||||
// return {
|
||||
// repeat: {
|
||||
// count: 0,
|
||||
// sequence: [],
|
||||
// }
|
||||
// }
|
||||
// case 'Wait':
|
||||
// return {
|
||||
// wait_template: ""
|
||||
// }
|
||||
// case 'Event':
|
||||
// return {
|
||||
// event: "",
|
||||
// event_data: {}
|
||||
// }
|
||||
// case "Device":
|
||||
// return {
|
||||
// type: "",
|
||||
// device_id: "",
|
||||
// entity_id: "",
|
||||
// domain: "",
|
||||
// }
|
||||
// case "Choose":
|
||||
// return {
|
||||
// choose: [],
|
||||
// default: [],
|
||||
// }
|
||||
}
|
||||
}
|
||||
// else if (node_type === "condition") {
|
||||
// if (node_subtype in ['And', 'Or', 'Noe']) {
|
||||
// return {
|
||||
// condition: node_subtype.toLowerCase(),
|
||||
// conditions: [],
|
||||
// }
|
||||
// } else if (node_subtype === 'Numeric State') {
|
||||
// return {
|
||||
// condition: "numeric_state",
|
||||
// entity_id: ""
|
||||
// }
|
||||
// } else if (node_subtype === 'State') {
|
||||
// return {
|
||||
// condition: "state",
|
||||
// entity_id: "",
|
||||
// state: "",
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
throw new Error(`Invalid or Not implemented node type ${node_type} -> ${node_subtype}`)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { AutomationNode } from "./types";
|
||||
|
||||
|
||||
export const getNameFromAction = (action: AutomationNode): string => {
|
||||
if(typeof action === 'string') {
|
||||
return action;
|
||||
}
|
||||
if ('alias' in action && action.alias){
|
||||
return action.alias;
|
||||
}
|
||||
if ('service' in action) {
|
||||
return action.service
|
||||
}
|
||||
if ('repeat' in action) {
|
||||
return 'Repeat'
|
||||
}
|
||||
if ('wait_template' in action) {
|
||||
return 'Wait'
|
||||
}
|
||||
if ('event' in action) {
|
||||
return action.event
|
||||
}
|
||||
if ('type' in action) {
|
||||
return 'Device ' +action.type
|
||||
}
|
||||
if ('choose' in action) {
|
||||
return 'Choose'
|
||||
}
|
||||
return 'n/a'
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { useState } from "react";
|
||||
import { AutomationNodeType, AutomationNodeTypes } from "../../automation/types";
|
||||
import { typeList } from "../../automation/useNodeState";
|
||||
import InputList from "../InputList";
|
||||
import InputWrapper from "../InputWrapper";
|
||||
|
||||
export interface Props<T extends AutomationNodeType> {
|
||||
node_type: T,
|
||||
onClose: () => void,
|
||||
onCreate: (newnode: AutomationNodeTypes[T]) => void,
|
||||
}
|
||||
export default function NewNodeModal<T extends AutomationNodeType>({
|
||||
node_type,
|
||||
onClose,
|
||||
onCreate,
|
||||
}: Props<T>) {
|
||||
const [selectedSubType, setSubType] = useState<string>(typeList[node_type][0]);
|
||||
|
||||
return <div className="new-node-modal">
|
||||
<div className="new-node-modal--background" onClick={() => onClose()}></div>
|
||||
<div className="new-node-modal--inner" onClick={e => e.preventDefault()}>
|
||||
<div className="new-node-modal--title">Create {node_type[0].toUpperCase()}{node_type.slice(1)}</div>
|
||||
<div className="new-node-modal--body">
|
||||
<InputWrapper label="Type:">
|
||||
<InputList options={typeList[node_type]} current={selectedSubType} onChange={n => setSubType(n)}/>
|
||||
</InputWrapper>
|
||||
</div>
|
||||
<div className="new-node-modal--footer">
|
||||
<button className="secondary" onClick={() => onClose()}>Close</button>
|
||||
<button onClick={() => onCreate({} as any)}>Create</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { useState } from "react";
|
||||
import * as types from "../../automation/types";
|
||||
import { getNameFromAction } from "../../automation/utils";
|
||||
import AutomationNode from "../Node";
|
||||
import NewNodeModal from "./NewNodeModal";
|
||||
|
||||
export interface Props {
|
||||
automation: types.Automation;
|
||||
}
|
||||
export default function AutomationEditor({ automation }: Props) {
|
||||
// state
|
||||
const [modalState, setModalState] = useState<types.AutomationNodeType | null>(null);
|
||||
const [state, setState] = useState(automation);
|
||||
|
||||
// helper state functions
|
||||
const addNode = <T extends types.AutomationNodeType>(node_type: T, node: types.AutomationNodeTypes[T]) => {
|
||||
const nodes: types.AutomationNode[] = state[node_type];
|
||||
setState({
|
||||
...state,
|
||||
[node_type]: nodes.concat([node as any])
|
||||
});
|
||||
}
|
||||
const removeNode = <T extends types.AutomationNodeType>(node_type: T, node_id: number) => {
|
||||
const nodes: types.AutomationNode[] = state[node_type];
|
||||
setState({
|
||||
...state,
|
||||
[node_type]: nodes
|
||||
.slice(0, node_id)
|
||||
.concat(
|
||||
nodes.slice(
|
||||
node_id + 1,
|
||||
nodes.length
|
||||
)
|
||||
)
|
||||
});
|
||||
}
|
||||
// helper element functions
|
||||
const makeChild = (node_type: types.AutomationNodeType) => {
|
||||
const nodes: types.AutomationNode[] = state[node_type];
|
||||
return [
|
||||
<div className="automation-box--elm-list" key="list">
|
||||
{state[node_type].map((n, i) => (
|
||||
<AutomationNode
|
||||
key={i}
|
||||
title={getNameFromAction(n)}
|
||||
showX={false}
|
||||
initialOpenState={false}
|
||||
onXClick={() => removeNode(node_type, i)}
|
||||
/>
|
||||
))}
|
||||
</div>,
|
||||
<button
|
||||
key="btn"
|
||||
className="elm-list"
|
||||
onClick={() => setModalState(node_type)}
|
||||
>
|
||||
Add +
|
||||
</button>
|
||||
];
|
||||
}
|
||||
|
||||
return <div className="automation-editor">
|
||||
<AutomationNode
|
||||
title={`${automation.alias} (${automation.mode})`}
|
||||
initialOpenState={true}
|
||||
showChildren={true}
|
||||
showX={false}
|
||||
>
|
||||
<div className="automation-editor--root">
|
||||
<h4>Trigger</h4>
|
||||
{makeChild("trigger")}
|
||||
<h4>Condition</h4>
|
||||
{makeChild("condition")}
|
||||
<h4>Actions</h4>
|
||||
{makeChild("action")}
|
||||
</div>
|
||||
</AutomationNode>
|
||||
{modalState && <NewNodeModal
|
||||
node_type={modalState}
|
||||
onClose={() => setModalState(null)}
|
||||
onCreate={node => {
|
||||
addNode(modalState, node);
|
||||
setModalState(null);
|
||||
}}
|
||||
/>}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { SelectHTMLAttributes } from "react";
|
||||
|
||||
|
||||
export interface Props {
|
||||
current: string;
|
||||
options: readonly string[];
|
||||
onChange: (n: string) => void;
|
||||
id?: string;
|
||||
className?: string;
|
||||
}
|
||||
export default function InputList({current, options, onChange, ...selattr}: Props) {
|
||||
return <select {...selattr} value={current} onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.currentTarget.value);
|
||||
}}>
|
||||
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
|
||||
</select>
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PropsWithChildren } from "react";
|
||||
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
}
|
||||
export default function InputWrapper({label, children}: PropsWithChildren<Props>) {
|
||||
return <div className="input-wrapper">
|
||||
<label>{label}</label>
|
||||
{children}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { PropsWithChildren, useState } from "react";
|
||||
|
||||
export interface Props {
|
||||
title: string;
|
||||
showX?: boolean;
|
||||
showChildren?: boolean;
|
||||
initialOpenState?: boolean;
|
||||
onXClick?: () => void;
|
||||
}
|
||||
export default function AutomationNode({
|
||||
children,
|
||||
title,
|
||||
showX=false,
|
||||
showChildren=false,
|
||||
initialOpenState=false,
|
||||
onXClick = () => {},
|
||||
}: PropsWithChildren<Props>) {
|
||||
const [isOpen, setOpen] = useState(initialOpenState);
|
||||
console.log(children);
|
||||
return <div className="automation-node">
|
||||
<div className="automation-node-inner">
|
||||
<div
|
||||
className="automation-node-inner-edge left"
|
||||
onClick={() => onXClick()}
|
||||
>
|
||||
{showX && (
|
||||
<div className="automation-node-side-button">X</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="automation-node-inner-text">{title}</div>
|
||||
<div
|
||||
className="automation-node-inner-edge right"
|
||||
onClick={() => setOpen(!isOpen)}
|
||||
>
|
||||
{showChildren && <div className="automation-node-side-button">{isOpen ? "▲" : "▼"}</div>}
|
||||
</div>
|
||||
</div>
|
||||
{showChildren&&<div className={`automation-node-children ${isOpen ? "open" : "closed"}`}>
|
||||
{children}
|
||||
</div>}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
name="viewport"
|
||||
/>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
|
||||
<meta name="application-name" content="MurderFriends" />
|
||||
<meta name="apple-mobile-web-app-title" content="MurderFriends" />
|
||||
|
||||
<meta name="msapplication-starturl" content="/" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, shrink-to-fit=no"
|
||||
/>
|
||||
|
||||
<link rel="stylesheet" href="styles/index.scss" />
|
||||
|
||||
<title>Shortumation</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="app"></div>
|
||||
<script src="main.tsx" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
import ReactDOM from "react-dom";
|
||||
import App from "./router";
|
||||
|
||||
const app = document.getElementById("app");
|
||||
|
||||
ReactDOM.render(<App />, app);
|
||||
@@ -0,0 +1,22 @@
|
||||
import AutomationEditor from "../components/AutomationEditor";
|
||||
import sample from "../sample/auto_01.yaml";
|
||||
|
||||
console.log(sample)
|
||||
|
||||
export function Home() {
|
||||
return (
|
||||
<div id="page--home" className="page">
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-around",
|
||||
alignItems: "center",
|
||||
width: "100vw"
|
||||
}}
|
||||
>
|
||||
<AutomationEditor automation={sample}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import React from "react";
|
||||
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
|
||||
import { Home } from "./pages/Home";
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Router>
|
||||
<div>
|
||||
<Switch>
|
||||
<Route path="/">
|
||||
<Home />
|
||||
</Route>
|
||||
</Switch>
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
alias: On Balcony Door Open
|
||||
description: "Determines what to do when the door opens..."
|
||||
trigger:
|
||||
- type: opened
|
||||
platform: device
|
||||
device_id: bad6b55ae91b7ced810fd5310c0a0fce
|
||||
entity_id: binary_sensor.door_balcony
|
||||
domain: binary_sensor
|
||||
condition: []
|
||||
action:
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ states('switch.plug_out_bug_lamp') == 'unavailable' }}"
|
||||
sequence:
|
||||
- type: turn_on
|
||||
device_id: 03065414e37dafc42ce0597f5458a084
|
||||
entity_id: switch.plug_balcony_power
|
||||
domain: switch
|
||||
- wait_template: "{{ states('switch.plug_out_bug_lamp') != 'unavailable' }}"
|
||||
timeout: "00:05:00"
|
||||
- type: turn_on
|
||||
device_id: 687cb5b66de19eaab5eb64cbaad90c58
|
||||
entity_id: switch.plug_out_bug_lamp
|
||||
domain: switch
|
||||
default:
|
||||
- type: turn_on
|
||||
device_id: 687cb5b66de19eaab5eb64cbaad90c58
|
||||
entity_id: switch.plug_out_bug_lamp
|
||||
domain: switch
|
||||
mode: single
|
||||
@@ -0,0 +1,3 @@
|
||||
import 'jest-extended'
|
||||
import 'jest-dom/extend-expect'
|
||||
import 'react-testing-library/cleanup-after-each'
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
||||
@@ -0,0 +1,9 @@
|
||||
$primary: #111111;
|
||||
$secondary: #1c1c1c;
|
||||
$primary-accent: #bbbbbb;
|
||||
$secondary-accent: #929191;
|
||||
|
||||
$font-color-primary: #e1e1e1;
|
||||
|
||||
$green: #68caa4;
|
||||
$blue: #68aaca;
|
||||
@@ -0,0 +1,17 @@
|
||||
.automation-editor {
|
||||
&--root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
button.elm-list {
|
||||
width: 90%;
|
||||
}
|
||||
&--elm-list {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 5%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
.automation-node {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
&-inner {
|
||||
padding: 10px;
|
||||
border-radius: 25px;
|
||||
background-color: $secondary;
|
||||
max-width: 200px;
|
||||
max-height: 75px;
|
||||
min-width: 200px;
|
||||
min-height: 75px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-around;
|
||||
|
||||
&-text {
|
||||
flex: 2;
|
||||
display: flex;
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
&-edge {
|
||||
flex: 1;
|
||||
border-radius: 30px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
&.left {
|
||||
border-left: 1px $secondary-accent solid;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
&.right {
|
||||
border-right: 1px $secondary-accent solid;
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
&:hover {
|
||||
background-color: $primary-accent;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
&-children {
|
||||
min-width: 250px;
|
||||
padding: 2.5px;
|
||||
|
||||
&.closed {
|
||||
height: 0;
|
||||
width: 0;
|
||||
display: none;
|
||||
}
|
||||
&.open {
|
||||
border-radius: 25px;
|
||||
border-color: $secondary-accent;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
.input-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
label {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
.new-node-modal {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
left: 0;
|
||||
top: 0;
|
||||
&--background {
|
||||
position: absolute;
|
||||
z-index: 0;
|
||||
width: 100vw;
|
||||
height: 100vw;
|
||||
background-color: rgba($secondary, 0.5);
|
||||
}
|
||||
|
||||
&--inner {
|
||||
z-index: 1;
|
||||
max-width: 80%;
|
||||
max-height: 60%;
|
||||
min-height: 200px;
|
||||
min-width: 200px;
|
||||
border-radius: 20px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: $primary;
|
||||
border: 1px solid $primary-accent;
|
||||
}
|
||||
&--title {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
&--body {
|
||||
flex-grow: 1;
|
||||
}
|
||||
&--footer {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
@import "./AutomationNode.scss";
|
||||
@import "./AutomationEditor.scss";
|
||||
@import "./NewNodeModal.scss";
|
||||
@import "./InputWrapper.scss";
|
||||
@@ -0,0 +1,105 @@
|
||||
@import "./colors.scss";
|
||||
@import "./pages/index.scss";
|
||||
@import "./utils.scss";
|
||||
@import "./components/index.scss";
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
font-family: Tahoma, Geneva, sans-serif;
|
||||
background-color: $primary;
|
||||
display: grid;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
color: $font-color-primary;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5 {
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
::-webkit-scrollbar-track {
|
||||
background: $secondary;
|
||||
}
|
||||
|
||||
/* Handle */
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: $secondary-accent;
|
||||
}
|
||||
|
||||
/* Handle on hover */
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: $primary-accent;
|
||||
}
|
||||
|
||||
:root {
|
||||
touch-action: pan-x pan-y;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: $secondary;
|
||||
color: $primary-accent;
|
||||
border-color: $primary-accent;
|
||||
&:hover {
|
||||
background-color: $primary;
|
||||
border-color: $secondary-accent;
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background-color: $primary;
|
||||
color: $secondary-accent;
|
||||
border-color: $secondary-accent;
|
||||
&:hover {
|
||||
background-color: $secondary;
|
||||
border-color: $primary-accent;
|
||||
}
|
||||
}
|
||||
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
padding: 2.5%;
|
||||
margin-left: 5%;
|
||||
margin-right: 5%;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
select {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#page--home {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
@import "./Home.scss";
|
||||
|
||||
.page {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
font-size: 16px;
|
||||
color: $font-color-primary;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
> div {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
.box {
|
||||
background-color: $secondary;
|
||||
max-width: 80%;
|
||||
max-height: 30%;
|
||||
min-width: 80%;
|
||||
min-height: 30%;
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"jsx": "react-jsx",
|
||||
"rootDir": "./src",
|
||||
"experimentalDecorators": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["dom", "es2015"]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": ["tslint-react", "tslint-config-prettier"],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"variable-name": false,
|
||||
"function-name": false,
|
||||
"jsx-no-lambda": false
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
+4797
File diff suppressed because it is too large.
Load diff
+6706
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user