Browse Source

Fixed lint issues

update-deps
Alex Mikhalev 8 years ago
parent
commit
9668e8aeab
  1. 8
      app/script/mqtt.ts
  2. 66
      app/script/sprinklers.ts
  3. 12
      app/script/ui.ts
  4. 9
      app/script/utils.ts
  5. 2
      package.json

8
app/script/mqtt.ts

@ -185,10 +185,10 @@ class MqttSprinklersDevice extends SprinklersDevice {
runSection(section: Section | number, duration: Duration) { runSection(section: Section | number, duration: Duration) {
const sectionNum = checkedIndexOf(section, this.sections, "Section"); const sectionNum = checkedIndexOf(section, this.sections, "Section");
return this.makeRequest(`sections/${sectionNum}/run`, const payload: IRunSectionJSON = {
{ duration: duration.toSeconds(),
duration: duration.toSeconds(), };
} as IRunSectionJSON); return this.makeRequest(`sections/${sectionNum}/run`, payload);
} }
runProgram(program: Program | number) { runProgram(program: Program | number) {

66
app/script/sprinklers.ts

@ -1,23 +1,23 @@
import { observable, IObservableArray } from "mobx"; import { observable, IObservableArray } from "mobx";
export abstract class Section { export abstract class Section {
public device: SprinklersDevice; device: SprinklersDevice;
@observable @observable
public name: string = ""; name: string = "";
@observable @observable
public state: boolean = false; state: boolean = false;
constructor(device: SprinklersDevice) { constructor(device: SprinklersDevice) {
this.device = device; this.device = device;
} }
public run(duration: Duration) { run(duration: Duration) {
return this.device.runSection(this, duration); return this.device.runSection(this, duration);
} }
public toString(): string { toString(): string {
return `Section{name="${this.name}", state=${this.state}}`; return `Section{name="${this.name}", state=${this.state}}`;
} }
} }
@ -34,30 +34,30 @@ export enum Weekday {
} }
export class Schedule { export class Schedule {
public times: ITimeOfDay[] = []; times: ITimeOfDay[] = [];
public weekdays: Weekday[] = []; weekdays: Weekday[] = [];
public from?: Date = null; from?: Date = null;
public to?: Date = null; to?: Date = null;
} }
export class Duration { export class Duration {
public static fromSeconds(seconds: number): Duration { static fromSeconds(seconds: number): Duration {
return new Duration(Math.floor(seconds / 60), seconds % 60); return new Duration(Math.floor(seconds / 60), seconds % 60);
} }
public minutes: number = 0; minutes: number = 0;
public seconds: number = 0; seconds: number = 0;
constructor(minutes: number, seconds: number) { constructor(minutes: number, seconds: number) {
this.minutes = minutes; this.minutes = minutes;
this.seconds = seconds; this.seconds = seconds;
} }
public toSeconds(): number { toSeconds(): number {
return this.minutes * 60 + this.seconds; return this.minutes * 60 + this.seconds;
} }
public withSeconds(newSeconds: number): Duration { withSeconds(newSeconds: number): Duration {
let newMinutes = this.minutes; let newMinutes = this.minutes;
if (newSeconds >= 60) { if (newSeconds >= 60) {
newMinutes++; newMinutes++;
@ -70,14 +70,14 @@ export class Duration {
return new Duration(newMinutes, newSeconds); return new Duration(newMinutes, newSeconds);
} }
public withMinutes(newMinutes: number): Duration { withMinutes(newMinutes: number): Duration {
if (newMinutes < 0) { if (newMinutes < 0) {
newMinutes = 0; newMinutes = 0;
} }
return new Duration(newMinutes, this.seconds); return new Duration(newMinutes, this.seconds);
} }
public toString(): string { toString(): string {
return `${this.minutes}M ${this.seconds}S`; return `${this.minutes}M ${this.seconds}S`;
} }
} }
@ -90,31 +90,31 @@ export interface IProgramItem {
} }
export class Program { export class Program {
public device: SprinklersDevice; device: SprinklersDevice;
constructor(device: SprinklersDevice) {
this.device = device;
}
@observable @observable
public name: string = ""; name: string = "";
@observable @observable
public enabled: boolean = false; enabled: boolean = false;
@observable @observable
public schedule: Schedule = new Schedule(); schedule: Schedule = new Schedule();
@observable @observable
public sequence: IProgramItem[] = []; sequence: IProgramItem[] = [];
@observable @observable
public running: boolean = false; running: boolean = false;
constructor(device: SprinklersDevice) {
this.device = device;
}
public run() { run() {
return this.device.runProgram(this); return this.device.runProgram(this);
} }
public toString(): string { toString(): string {
return `Program{name="${this.name}", enabled=${this.enabled}, schedule=${this.schedule}, return `Program{name="${this.name}", enabled=${this.enabled}, schedule=${this.schedule},
sequence=${this.sequence}, running=${this.running}}`; sequence=${this.sequence}, running=${this.running}}`;
} }
@ -126,17 +126,17 @@ export class SectionRunner {
export abstract class SprinklersDevice { export abstract class SprinklersDevice {
@observable @observable
public connected: boolean = false; connected: boolean = false;
@observable @observable
public sections: IObservableArray<Section> = [] as IObservableArray<Section>; sections: IObservableArray<Section> = [] as IObservableArray<Section>;
@observable @observable
public programs: IObservableArray<Program> = [] as IObservableArray<Program>; programs: IObservableArray<Program> = [] as IObservableArray<Program>;
public abstract runSection(section: number | Section, duration: Duration): Promise<{}>; abstract runSection(section: number | Section, duration: Duration): Promise<{}>;
public abstract runProgram(program: number | Program): Promise<{}>; abstract runProgram(program: number | Program): Promise<{}>;
abstract get id(): string; abstract get id(): string;
} }

12
app/script/ui.ts

@ -1,10 +1,10 @@
import {observable} from "mobx"; import {observable} from "mobx";
export class Message { export class Message {
public id: string; id: string;
public header: string = ""; header: string = "";
public content: string = ""; content: string = "";
public type: Message.Type = Message.Type.Default; type: Message.Type = Message.Type.Default;
constructor(header: string, content: string = "", type: Message.Type = Message.Type.Default) { constructor(header: string, content: string = "", type: Message.Type = Message.Type.Default) {
this.id = "" + Math.floor(Math.random() * 1000000000); this.id = "" + Math.floor(Math.random() * 1000000000);
@ -22,9 +22,9 @@ export namespace Message {
export class UiStore { export class UiStore {
@observable @observable
public messages: Message[] = []; messages: Message[] = [];
public addMessage(message: Message) { addMessage(message: Message) {
this.messages.push(message); this.messages.push(message);
} }
} }

9
app/script/utils.ts

@ -1,10 +1,7 @@
export function checkedIndexOf<T>(o: T | number, arr: T[], type: string = "object"): number { export function checkedIndexOf<T>(o: T | number, arr: T[], type: string = "object"): number {
let idx: number; const idx = (typeof o === "number")
if (typeof o === "number") { ? o
idx = o; : arr.indexOf(o);
} else {
idx = arr.indexOf(o);
}
if (idx < 0 || idx > arr.length) { if (idx < 0 || idx > arr.length) {
throw new Error(`Invalid ${type} specified: ${o}`); throw new Error(`Invalid ${type} specified: ${o}`);
} }

2
package.json

@ -9,7 +9,7 @@
"clean": "rm -rf ./dist ./build", "clean": "rm -rf ./dist ./build",
"build": "webpack --config ./webpack/prod.config.js", "build": "webpack --config ./webpack/prod.config.js",
"start": "webpack-dev-server --config ./webpack/dev.config.js", "start": "webpack-dev-server --config ./webpack/dev.config.js",
"lint": "tslint app/script/**/* --force" "lint": "tslint \"app/script/**/*\" --force"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

Loading…
Cancel
Save