This repository was archived by the owner on Sep 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export interface ControllerInfo {
4
4
version : string ;
5
5
chipID : string ;
6
6
lux : number ;
7
+ powerOn : boolean ;
7
8
network : Network ;
8
9
roomWeather : RoomWeather ;
9
10
}
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ export class Server {
11
11
private readonly apps : App [ ] = [ ] ;
12
12
private readonly controller : SmartDisplayController ;
13
13
14
- private powerOn = true ;
15
14
private currentAppIndex = 0 ;
16
15
private appIterations = 0 ;
17
16
@@ -55,7 +54,9 @@ export class Server {
55
54
switch ( command ) {
56
55
case 'power' : {
57
56
if ( message === 'on' || message === 'off' ) {
58
- this . powerOn = message === 'on' ? true : false ;
57
+ const powerOn = message === 'on' ? true : false ;
58
+
59
+ this . controller . power ( powerOn ) ;
59
60
}
60
61
61
62
break ;
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import { MqttHelper } from './helper';
15
15
export class SmartDisplayController {
16
16
private readonly _info = new LastUpdated < ControllerInfo > ( ) ;
17
17
18
+ private _powerStatus : boolean = true ; // true = on; false = off
19
+
18
20
get info ( ) : ControllerInfo | null {
19
21
// TODO return NULL if data too old
20
22
return this . _info . value ;
@@ -46,6 +48,22 @@ export class SmartDisplayController {
46
48
switch ( command ) {
47
49
case 'info' : {
48
50
this . _info . value = JSON . parse ( message ) ;
51
+
52
+ const powerOnDevice = this . _info . value ?. powerOn ;
53
+
54
+ // check power status
55
+ if ( powerOnDevice !== this . _powerStatus ) {
56
+ // inconsistence detected
57
+ console . warn (
58
+ 'power status inconstistence:' ,
59
+ `server: ${ this . _powerStatus } ` ,
60
+ `device: ${ powerOnDevice } `
61
+ ) ;
62
+
63
+ // fix status
64
+ this . power ( this . _powerStatus ) ;
65
+ }
66
+
49
67
break ;
50
68
}
51
69
}
@@ -111,6 +129,18 @@ export class SmartDisplayController {
111
129
) ;
112
130
}
113
131
132
+ power ( status : boolean ) : void {
133
+ this . _powerStatus = status ;
134
+
135
+ const dataOut = {
136
+ on : status
137
+ } ;
138
+ this . client . publish (
139
+ 'smartDisplay/client/in/power' ,
140
+ JSON . stringify ( dataOut )
141
+ ) ;
142
+ }
143
+
114
144
destroy ( ) : void {
115
145
this . client . end ( true ) ;
116
146
}
You can’t perform that action at this time.
0 commit comments