This commit is contained in:
Ari committed 2022-04-13 13:37:44 -04:00
commit 38c312f849
10 files changed
+253 -25

No files matched your search

+4
View File
@@ -12,3 +12,7 @@ local_logs:
local_ps:
$(DC) ps
local_stop:
$(DC) stop
+2
View File
@@ -8,7 +8,9 @@ from .loader import HassConfig
def find_hass_config() -> HassConfig:
"""Try to find HASS config."""
if config("USE_EXAMPLE_REPO", False, cast=bool):
print("using USE_EXAMPLE_REPO")
from tests.utils import create_copy_of_example_config
return HassConfig(create_copy_of_example_config())
if "HASSIO_TOKEN" in os.environ:
+2 -2
View File
@@ -2,7 +2,7 @@
"name": "webapp",
"version": "0.1.0",
"private": true,
"homepage": "./",
"homepage": ".",
"dependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
@@ -71,4 +71,4 @@
"@types/js-yaml": "^4.0.5",
"ts-node": "^10.4.0"
}
}
}
+20 -20
View File
@@ -1,21 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="An easier way to maintain automations & scripts in
home-assistant"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="An easier way to maintain automations & scripts in
home-assistant" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
@@ -24,10 +22,12 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Shortumations</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
<title>Shortumations</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
@@ -1,5 +1,5 @@
import { FC } from "react";
import { AutomationCondition, LogicCondition, NumericCondition, TemplateCondition } from "types/automations/conditions";
import { AutomationCondition, LogicCondition, NumericCondition, StateCondition, TemplateCondition, TimeCondition } from "types/automations/conditions";
import { getDescriptionFromAutomationNode } from "utils/formatting";
import InputNumber from "components/Inputs/InputNumber";
import InputText from "components/Inputs/InputText";
@@ -7,6 +7,7 @@ import InputTextArea from "components/Inputs/InputTextArea";
import { InputEntity } from "components/Inputs/InputTextBubble";
import { ConditionNode } from "./ConditionNode";
import { genUpdateMethods } from "./nestedUpdater";
import InputTime from "components/Inputs/InputTime";
interface Editor<C extends AutomationCondition> extends FC<{
@@ -27,6 +28,10 @@ export const getEditor = (condition: AutomationCondition): Editor<any> => {
return LogicViewer;
case 'numeric_state':
return NumericStateEditor;
case 'state':
return StateEditor;
case 'time':
return TimeEditor;
default:
return () => <div>Not Ready</div>
}
@@ -134,3 +139,97 @@ export const LogicViewer: Editor<LogicCondition> = ({
})}
</>
}
export const StateEditor: Editor<StateCondition> = ({
onChange,
condition,
}) => {
return <div>
<InputText label="Alias" value={condition.condition_data.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
...condition,
condition_data: {
...condition.condition_data,
alias
}
})} />
<InputEntity
value={condition.condition_data.entity_id}
onChange={entity_id => onChange({
...condition,
condition_data: {
...condition.condition_data,
entity_id
}
})}
/>
<InputText label="Attribute" value={condition.condition_data.attribute ?? ""} onChange={attribute => onChange({
...condition,
condition_data: {
...condition.condition_data,
attribute
}
})} />
<InputText
label="State"
value={String(condition.condition_data.state)}
onChange={state => onChange({
...condition,
condition_data: {
...condition.condition_data,
state,
}
})}
/>
<InputTime
label="For"
value={condition.condition_data.for}
onChange={_for => onChange({
...condition,
condition_data: {
...condition.condition_data,
for: _for,
}
})}
/>
</div>
}
export const TimeEditor: Editor<TimeCondition> = ({
onChange,
condition,
}) => {
return <div>
<InputText label="Alias" value={condition.condition_data.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
...condition,
condition_data: {
...condition.condition_data,
alias
}
})} />
<InputTime
label="After"
value={condition.condition_data.after}
onChange={after => onChange({
...condition,
condition_data: {
...condition.condition_data,
after,
}
})}
/>
<InputTime
label="Before"
value={condition.condition_data.before}
onChange={before => onChange({
...condition,
condition_data: {
...condition.condition_data,
before,
}
})}
/>
<b>Weekday not support for no, use yaml for now</b> {condition.condition_data.weekday}
</div>
}
@@ -0,0 +1,27 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { useState } from "react";
import { AutomationTime } from "types/automations/common";
import InputTime from "./InputTime";
export default {
title: 'Inputs/InputTime',
component: InputTime,
parameters: { actions: { argTypesRegex: '^on.*' } },
} as ComponentMeta<typeof InputTime>;
const Template: ComponentStory<typeof InputTime> = args => {
const [value, setValue] = useState<AutomationTime>({
})
return <div className="page">
<InputTime {...args} value={value} onChange={setValue} />
</div>
}
export const SimpleText = Template.bind({})
SimpleText.args = {
label: "Time Stamp",
}
@@ -0,0 +1,56 @@
import { PropsWithChildren, useState } from "react";
import { AutomationTime } from "types/automations/common";
import { milisecondsToObject } from "utils/time";
import InputWrapper from "./InputWrapper";
import { useInputTimeStyles } from "./styles";
export interface Props {
textBoxFor?: string;
label: string;
value?: AutomationTime;
onChange: (v?: AutomationTime) => void;
onEnter?: () => void;
}
export default function InputTime({
label,
textBoxFor,
value = {},
onChange,
onEnter = () => { },
children,
}: PropsWithChildren<Props>) {
let cleanValue = '';
if (value) {
const {
hours,
minutes,
seconds,
milliseconds,
} = value;
cleanValue = [hours, minutes, seconds].map(x => String(x).padStart(2, '0')).join(':') + `.${String(milliseconds).padStart(3, '0')}`;
}
const { classes } = useInputTimeStyles({});
const [isFocused, setIsFocused] = useState(false)
return <InputWrapper className={classes.wrapper} label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
<input
className={classes.input}
type="time"
step={0.001}
value={cleanValue}
onKeyDown={e => {
if (e.key === 'Enter') {
onEnter();
}
}}
onChange={e => {
e.preventDefault();
onChange(milisecondsToObject(e.target.valueAsNumber))
}}
onBlur={e => {
setIsFocused(false)
}}
/>
<button onClick={() => onChange()} className={classes.cancel}>X</button>
{children}
</InputWrapper>
}
@@ -6,10 +6,11 @@ export interface Props {
label: string;
labelSize?: 'normal' | 'small';
noMargin?: boolean;
className?: string;
}
const InputWrapper: FC<Props> = ({ label, children, labelSize = 'normal', noMargin = false }) => {
const InputWrapper: FC<Props> = ({ label, children, labelSize = 'normal', noMargin = false, className = "" }) => {
const { classes } = useInputWrapperStyles({ labelSize, noMargin })
return <div className={classes.wrapper}>
return <div className={[classes.wrapper, className].join(" ")}>
<label className={classes.label}>{label}</label>
{children}
</div>
+26
View File
@@ -62,6 +62,32 @@ export const useInputTextStyles = createAppUseStyles<{}>(theme => ({
...commonInputStyle(theme),
}));
export const useInputTimeStyles = createAppUseStyles<{}>(theme => ({
input: {
...commonInputStyle(theme).input,
flex: 1,
},
wrapper: {
flexDirection: 'row !important',
justifyContent: 'center',
alignItems: 'center',
},
cancel: {
cursor: 'pointer',
maxWidth: "2em",
maxHeight: "2em",
fontSize: '1em',
padding: "0.25em 0.5em",
borderRadius: '20px',
background: theme.primary,
color: theme.primaryAccent,
borderColor: theme.primaryAccent,
borderStyle: "solid",
borderWidth: '1.5px',
},
}));
export const useInputNumberStyles = createAppUseStyles<{}>(theme => {
const styles = commonInputStyle(theme);
return {
+13
View File
@@ -0,0 +1,13 @@
import { AutomationTime } from "types/automations/common";
const cleanTime = (t: number) => Math.max(0, Math.floor(t))
export const milisecondsToObject = (total_miliseconds: number): AutomationTime => {
const hours = cleanTime(total_miliseconds / (60 * 60 * 1000));
const minutes = cleanTime((total_miliseconds - hours * 60 * 60 * 1000) / (60 * 1000));
const seconds = cleanTime((total_miliseconds - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000);
const milliseconds = total_miliseconds - hours * 60 * 60 * 1000 - minutes * 60 * 1000 - seconds * 1000;
return {
hours, minutes, seconds, milliseconds,
}
}