Extracted Duration from sprinklers
This commit is contained in:
parent
8ea82950fa
commit
3ce9bb4116
@ -1,7 +1,7 @@
|
||||
import * as React from "react";
|
||||
import { Input, InputProps } from "semantic-ui-react";
|
||||
|
||||
import { Duration } from "@common/sprinklers";
|
||||
import { Duration } from "@common/Duration";
|
||||
|
||||
export default class DurationInput extends React.Component<{
|
||||
duration: Duration,
|
||||
|
@ -2,6 +2,7 @@ import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { Table } from "semantic-ui-react";
|
||||
|
||||
import { Duration } from "@common/Duration";
|
||||
import { Program, Schedule } from "@common/sprinklers";
|
||||
|
||||
@observer
|
||||
@ -20,10 +21,12 @@ export default class ProgramTable extends React.Component<{ programs: Program[]
|
||||
return null;
|
||||
}
|
||||
const { name, running, enabled, schedule, sequence } = program;
|
||||
const sequenceItems = sequence.map((item, index) => (
|
||||
<li key={index}>Section {item.section + 1 + ""} for
|
||||
{item.duration.minutes}M {item.duration.seconds}S</li>
|
||||
));
|
||||
const sequenceItems = sequence.map((item, index) => {
|
||||
const duration = Duration.fromSeconds(item.duration);
|
||||
return (
|
||||
<li key={index}>Section {item.section + 1 + ""} for {duration.toString()}</li>
|
||||
);
|
||||
});
|
||||
return [(
|
||||
<Table.Row key={i}>
|
||||
<Table.Cell className="program--number">{"" + (i + 1)}</Table.Cell>
|
||||
|
@ -3,8 +3,9 @@ import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { DropdownItemProps, DropdownProps, Form, Header, Segment } from "semantic-ui-react";
|
||||
|
||||
import { Duration } from "@common/Duration";
|
||||
import log from "@common/logger";
|
||||
import { Duration, Section } from "@common/sprinklers";
|
||||
import { Section } from "@common/sprinklers";
|
||||
import DurationInput from "./DurationInput";
|
||||
|
||||
@observer
|
||||
@ -17,7 +18,7 @@ export default class RunSectionForm extends React.Component<{
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
duration: new Duration(1, 1),
|
||||
duration: new Duration(0, 0),
|
||||
section: "",
|
||||
};
|
||||
}
|
||||
@ -67,7 +68,7 @@ export default class RunSectionForm extends React.Component<{
|
||||
}
|
||||
const section: Section = this.props.sections[this.state.section];
|
||||
const { duration } = this.state;
|
||||
section.run(duration)
|
||||
section.run(duration.toSeconds())
|
||||
.then((result) => log.debug({ result }, "requested section run"))
|
||||
.catch((err) => log.error(err, "error running section"));
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
import { observable } from "mobx";
|
||||
import { Duration } from "./Duration";
|
||||
import { Schedule } from "./schedule";
|
||||
import { SprinklersDevice } from "./SprinklersDevice";
|
||||
|
||||
export class ProgramItem {
|
||||
// the section number
|
||||
readonly section: number;
|
||||
// duration of the run
|
||||
readonly duration: Duration;
|
||||
// duration of the run, in seconds
|
||||
readonly duration: number;
|
||||
|
||||
constructor(section: number = 0, duration: Duration = new Duration()) {
|
||||
constructor(section: number = 0, duration: number = 0) {
|
||||
this.section = section;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { observable } from "mobx";
|
||||
import { Duration } from "./Duration";
|
||||
import { SprinklersDevice } from "./SprinklersDevice";
|
||||
|
||||
export class Section {
|
||||
@ -14,7 +13,8 @@ export class Section {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
run(duration: Duration) {
|
||||
/** duration is in seconds */
|
||||
run(duration: number) {
|
||||
return this.device.runSection({ sectionId: this.id, duration });
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
import { observable } from "mobx";
|
||||
import { Duration } from "./Duration";
|
||||
import { SprinklersDevice } from "./SprinklersDevice";
|
||||
|
||||
export class SectionRun {
|
||||
readonly sectionRunner: SectionRunner;
|
||||
readonly id: number;
|
||||
section: number;
|
||||
duration: Duration = new Duration();
|
||||
duration: number = 0;
|
||||
startTime: Date | null = null;
|
||||
pauseTime: Date | null = null;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
export * from "./Duration";
|
||||
// export * from "./Duration";
|
||||
export * from "./ISprinklersApi";
|
||||
export * from "./Program";
|
||||
export * from "./schedule";
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { Duration } from "./Duration";
|
||||
|
||||
export interface WithType<Type extends string = string> {
|
||||
type: Type;
|
||||
}
|
||||
@ -15,7 +13,7 @@ export type UpdateProgramResponse = Response<"updateProgram", { data: any }>;
|
||||
|
||||
export interface WithSection { sectionId: number; }
|
||||
|
||||
export type RunSectionData = WithSection & { duration: Duration };
|
||||
export type RunSectionData = WithSection & { duration: number };
|
||||
export type RunSectionReqeust = RunSectionData & WithType<"runSection">;
|
||||
export type RunSectionResponse = Response<"runSection", { runId: number }>;
|
||||
|
||||
|
@ -3,17 +3,7 @@ import {
|
||||
} from "serializr";
|
||||
import * as s from "..";
|
||||
|
||||
export const duration: PropSchema = {
|
||||
serializer: (d: s.Duration | null) =>
|
||||
d != null ? d.toSeconds() : null,
|
||||
deserializer: (json: any, done) => {
|
||||
if (typeof json === "number") {
|
||||
done(null, s.Duration.fromSeconds(json));
|
||||
} else {
|
||||
done(new Error(`Duration expects a number, not ${json}`), undefined);
|
||||
}
|
||||
},
|
||||
};
|
||||
export const duration: PropSchema = primitive();
|
||||
|
||||
export const date: PropSchema = {
|
||||
serializer: (jsDate: Date | null) => jsDate != null ?
|
||||
|
Loading…
x
Reference in New Issue
Block a user