Browse Source

Formatted everything and fixed lint issues

update-deps
Alex Mikhalev 8 years ago
parent
commit
5e491bbd33
  1. 16
      app/script/components/App.tsx
  2. 10
      app/script/components/DeviceView.tsx
  3. 2
      app/script/components/DurationInput.tsx
  4. 4
      app/script/components/MessagesView.tsx
  5. 4
      app/script/components/ProgramTable.tsx
  6. 8
      app/script/components/RunSectionForm.tsx
  7. 6
      app/script/components/SectionTable.tsx
  8. 58
      app/script/mqtt.ts
  9. 15
      app/script/sprinklers.ts
  10. 17
      tslint.json

16
app/script/components/App.tsx

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
import * as React from "react";
import DevTools from "mobx-react-devtools";
import "app/style/app.css";
import "font-awesome/css/font-awesome.css";
import {observer} from "mobx-react";
import {SprinklersDevice} from "../sprinklers";
import {Item} from "semantic-ui-react";
import {UiStore} from "../ui";
import {MessagesView, DeviceView} from ".";
import DevTools from "mobx-react-devtools";
import * as React from "react";
import "semantic-ui-css/semantic.css";
import "font-awesome/css/font-awesome.css";
import "app/style/app.css";
import {Item} from "semantic-ui-react";
import {DeviceView, MessagesView} from ".";
import {SprinklersDevice} from "../sprinklers";
import {UiStore} from "../ui";
@observer
export default class App extends React.PureComponent<{ device: SprinklersDevice, uiStore: UiStore }, any> {

10
app/script/components/DeviceView.tsx

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
import * as React from "react";
import {observer} from "mobx-react";
import {Item, Header} from "semantic-ui-react";
import FontAwesome = require("react-fontawesome");
import * as classNames from "classnames";
import {observer} from "mobx-react";
import * as React from "react";
import {Header, Item} from "semantic-ui-react";
import {ProgramTable, RunSectionForm, SectionTable} from ".";
import {SprinklersDevice} from "../sprinklers";
import {SectionTable, RunSectionForm, ProgramTable} from ".";
import FontAwesome = require("react-fontawesome");
const ConnectionState = ({connected}: { connected: boolean }) =>
<span className={classNames({

2
app/script/components/DurationInput.tsx

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
import * as React from "react";
import {Duration} from "../sprinklers";
import {Input} from "semantic-ui-react";
import {Duration} from "../sprinklers";
export default class DurationInput extends React.Component<{
duration: Duration,

4
app/script/components/MessagesView.tsx

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
import {observer} from "mobx-react";
import * as React from "react";
import {CSSTransitionGroup} from "react-transition-group";
import {observer} from "mobx-react";
import {UiStore, Message as UiMessage} from "../ui";
import {Message} from "semantic-ui-react";
import {Message as UiMessage, UiStore} from "../ui";
@observer
export default class MessagesView extends React.PureComponent<{ uiStore: UiStore }, {}> {

4
app/script/components/ProgramTable.tsx

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
import * as React from "react";
import {observer} from "mobx-react";
import {Program, Schedule} from "../sprinklers";
import * as React from "react";
import {Table} from "semantic-ui-react";
import {Program, Schedule} from "../sprinklers";
@observer
export class ScheduleView extends React.PureComponent<{ schedule: Schedule }, {}> {

8
app/script/components/RunSectionForm.tsx

@ -1,10 +1,10 @@ @@ -1,10 +1,10 @@
import * as React from "react";
import {SyntheticEvent} from "react";
import {computed} from "mobx";
import {observer} from "mobx-react";
import {Duration, Section} from "../sprinklers";
import {Segment, Header, Form, DropdownProps, DropdownItemProps} from "semantic-ui-react";
import * as React from "react";
import {SyntheticEvent} from "react";
import {DropdownItemProps, DropdownProps, Form, Header, Segment} from "semantic-ui-react";
import {DurationInput} from ".";
import {Duration, Section} from "../sprinklers";
@observer
export default class RunSectionForm extends React.Component<{

6
app/script/components/SectionTable.tsx

@ -1,10 +1,10 @@ @@ -1,10 +1,10 @@
import * as React from "react";
import {observer} from "mobx-react";
import * as classNames from "classnames";
import {observer} from "mobx-react";
import * as React from "react";
import {Table} from "semantic-ui-react";
import FontAwesome = require("react-fontawesome");
import {Section} from "../sprinklers";
import FontAwesome = require("react-fontawesome");
/* tslint:disable:object-literal-sort-keys */

58
app/script/mqtt.ts

@ -1,21 +1,22 @@ @@ -1,21 +1,22 @@
import "paho-mqtt";
import MQTT = Paho.MQTT;
import {EventEmitter} from "events";
import "paho-mqtt";
import {
SprinklersDevice, ISprinklersApi, Section, Program, Schedule, ITimeOfDay, Duration, SectionRunner, ISectionRun,
Duration,
ISectionRun,
ISprinklersApi,
ITimeOfDay,
Program,
Schedule,
Section,
SectionRunner,
SprinklersDevice,
} from "./sprinklers";
import {checkedIndexOf} from "./utils";
import MQTT = Paho.MQTT;
export class MqttApiClient extends EventEmitter implements ISprinklersApi {
private static newClientId() {
return "sprinklers3-MqttApiClient-" + Math.round(Math.random() * 1000);
}
client: MQTT.Client;
connected: boolean;
devices: { [prefix: string]: MqttSprinklersDevice } = {};
constructor() {
@ -26,6 +27,10 @@ export class MqttApiClient extends EventEmitter implements ISprinklersApi { @@ -26,6 +27,10 @@ export class MqttApiClient extends EventEmitter implements ISprinklersApi {
// (this.client as any).trace = (m => console.log(m));
}
private static newClientId() {
return "sprinklers3-MqttApiClient-" + Math.round(Math.random() * 1000);
}
start() {
console.log("connecting to mqtt with client id %s", this.client.clientId);
this.client.connect({
@ -106,6 +111,22 @@ class MqttSprinklersDevice extends SprinklersDevice { @@ -106,6 +111,22 @@ class MqttSprinklersDevice extends SprinklersDevice {
this.sectionRunner = new MqttSectionRunner(this);
}
get id(): string {
return this.prefix;
}
private get subscriptions() {
return [
`${this.prefix}/connected`,
`${this.prefix}/sections`,
`${this.prefix}/sections/+/#`,
`${this.prefix}/programs`,
`${this.prefix}/programs/+/#`,
`${this.prefix}/responses/+`,
`${this.prefix}/section_runner`,
];
}
doSubscribe() {
const c = this.apiClient.client;
this.subscriptions
@ -184,10 +205,6 @@ class MqttSprinklersDevice extends SprinklersDevice { @@ -184,10 +205,6 @@ class MqttSprinklersDevice extends SprinklersDevice {
console.warn(`MqttSprinklersDevice recieved invalid topic: ${topic}`);
}
get id(): string {
return this.prefix;
}
runSection(section: Section | number, duration: Duration) {
const sectionNum = checkedIndexOf(section, this.sections, "Section");
const payload: IRunSectionJSON = {
@ -228,23 +245,12 @@ class MqttSprinklersDevice extends SprinklersDevice { @@ -228,23 +245,12 @@ class MqttSprinklersDevice extends SprinklersDevice {
});
}
private get subscriptions() {
return [
`${this.prefix}/connected`,
`${this.prefix}/sections`,
`${this.prefix}/sections/+/#`,
`${this.prefix}/programs`,
`${this.prefix}/programs/+/#`,
`${this.prefix}/responses/+`,
`${this.prefix}/section_runner`,
];
}
}
interface IResponseData {
reqTopic: string;
error?: string;
[key: string]: any;
}

15
app/script/sprinklers.ts

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import { observable, IObservableArray } from "mobx";
import {IObservableArray, observable} from "mobx";
export abstract class Section {
device: SprinklersDevice;
@ -41,10 +41,6 @@ export class Schedule { @@ -41,10 +41,6 @@ export class Schedule {
}
export class Duration {
static fromSeconds(seconds: number): Duration {
return new Duration(Math.floor(seconds / 60), seconds % 60);
}
minutes: number = 0;
seconds: number = 0;
@ -53,6 +49,10 @@ export class Duration { @@ -53,6 +49,10 @@ export class Duration {
this.seconds = seconds;
}
static fromSeconds(seconds: number): Duration {
return new Duration(Math.floor(seconds / 60), seconds % 60);
}
toSeconds(): number {
return this.minutes * 60 + this.seconds;
}
@ -162,17 +162,18 @@ export abstract class SprinklersDevice { @@ -162,17 +162,18 @@ export abstract class SprinklersDevice {
@observable
sectionRunner: SectionRunner;
abstract get id(): string;
abstract runSection(section: number | Section, duration: Duration): Promise<{}>;
abstract runProgram(program: number | Program): Promise<{}>;
abstract cancelSectionRunById(id: number): Promise<{}>;
abstract get id(): string;
}
export interface ISprinklersApi {
start();
getDevice(id: string): SprinklersDevice;
removeDevice(id: string);

17
tslint.json

@ -11,15 +11,22 @@ @@ -11,15 +11,22 @@
"max-classes-per-file": [
false
],
"ordered-imports": false,
"ordered-imports": true,
"variable-name": [
"allow-leading-underscore"
],
"no-namespace": [
"allow-declarations"
],
"no-namespace": false,
"interface-name": false,
"member-access": [ true, "no-public" ]
"member-access": [
true,
"no-public"
],
"member-ordering": [
true,
{
"order": "fields-first"
}
]
},
"rulesDirectory": []
}
Loading…
Cancel
Save