-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b063d88
commit b3650e8
Showing
7 changed files
with
96 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { compareAsc, parseISO } from 'date-fns' | ||
import { IrrigationEventDocument } from './interfaces/irrigation-event-document.interface' | ||
import { DeviceState } from './enums/device-state.interface' | ||
|
||
const sortFn = (a: IrrigationEventDocument, b: IrrigationEventDocument) => compareAsc(parseISO(a._id), parseISO(b._id)) | ||
|
||
export class DeviceEvents { | ||
private deviceId: number | ||
private events: IrrigationEventDocument[] = [] | ||
private currentDeviceState?: DeviceState | ||
|
||
constructor(deviceId: number, events: IrrigationEventDocument[]) { | ||
this.deviceId = deviceId | ||
this.events = [...events].sort(sortFn) | ||
} | ||
|
||
public getDeviceId(): number { | ||
return this.deviceId | ||
} | ||
|
||
public getEvents(): IrrigationEventDocument[] { | ||
return [...this.events] | ||
} | ||
|
||
public getFirstEvent(): IrrigationEventDocument { | ||
return this.events[0] | ||
} | ||
|
||
public getLastEvent(): IrrigationEventDocument { | ||
return this.events[this.events.length - 1] | ||
} | ||
|
||
public setCurrentDeviceState(state: DeviceState | undefined) { | ||
this.currentDeviceState = state | ||
} | ||
|
||
public getCurrentDeviceState(): DeviceState | undefined { | ||
return this.currentDeviceState | ||
} | ||
|
||
public addEvent(event: IrrigationEventDocument) { | ||
this.events.push(event) | ||
this.events.sort(sortFn) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { DeviceState } from '../enums/device-state.interface' | ||
|
||
export interface DeviceStates { | ||
[deviceId: string]: DeviceState | undefined | ||
[deviceId: number]: DeviceState | undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters