1- import { FlowCardTrigger , FlowCardTriggerDevice } from "homey" ;
2- import { container , singleton } from "tsyringe" ;
1+ import { __ , FlowCardTrigger , FlowCardTriggerDevice , FlowToken } from "homey" ;
2+ import { container , registry , singleton } from "tsyringe" ;
33import { HeatingManagerService } from "../heating-manager" ;
44import { HeatingPlanRepositoryService } from "../heating-plan-repository" ;
55import { HeatingSchedulerService } from "../heating-scheduler" ;
@@ -11,14 +11,30 @@ import { ModeChangedTrigger, ModeChangedTriggerTokens } from "./ModeChanged";
1111import { SetLogStateAction } from "./SetLogState" ;
1212import { SetModeAction } from "./SetMode" ;
1313import { SetPlanStateAction } from "./SetPlanState" ;
14+ import { SetThermostatOverrideAction } from "./SetThermostatOverride" ;
1415import { ThermostatModeChangedTrigger , ThermostatModeChangedTriggerTokens } from "./ThermostatModeChanged" ;
1516
17+ const FLOWSERVICE_TOKEN = "FlowService" ;
18+
19+ // to break the cycling dependency
1620@singleton ( )
21+ @registry ( [ { token : FLOWSERVICE_TOKEN , useToken : FlowService } ] )
1722export class FlowService {
1823 private logger : ILogger ;
1924 private modeChangedTrigger ! : FlowCardTrigger < ModeChangedTriggerTokens , void > ;
2025 private thermostatModeChangedTrigger ! : FlowCardTriggerDevice < ThermostatModeChangedTriggerTokens , void > ;
2126
27+ private modeToken ! : FlowToken < string > ;
28+ private nextDateToken ! : FlowToken < string > ;
29+
30+ public get nextDate ( ) : FlowToken < string > {
31+ return this . nextDateToken ;
32+ }
33+
34+ public get mode ( ) : FlowToken < string > {
35+ return this . modeToken ;
36+ }
37+
2238 public get modeChanged ( ) : FlowCardTrigger < ModeChangedTriggerTokens , void > {
2339 return this . modeChangedTrigger ;
2440 }
@@ -43,10 +59,27 @@ export class FlowService {
4359 settings : container . resolve < SettingsManagerService > ( SettingsManagerService ) ,
4460 } ;
4561
46- [ ApplyAllAction , ApplyPlanAction , SetLogStateAction , SetModeAction , SetPlanStateAction ]
47- . forEach ( ( action ) => action ( ctx ) ) ;
62+ [
63+ ApplyAllAction ,
64+ ApplyPlanAction ,
65+ SetLogStateAction ,
66+ SetModeAction ,
67+ SetPlanStateAction ,
68+ SetThermostatOverrideAction ,
69+ ] . forEach ( ( action ) => {
70+ // tslint:disable-next-line: no-empty
71+ try { action ( ctx ) ; } catch { }
72+ } ) ;
4873
4974 this . modeChangedTrigger = ModeChangedTrigger ( ctx ) ;
5075 this . thermostatModeChangedTrigger = ThermostatModeChangedTrigger ( ctx ) ;
76+
77+ this . logger . information ( `Registering token mode` ) ;
78+ this . modeToken = new FlowToken < string > ( "mode" , { type : "string" , title : __ ( "plans.heatingmode.label" ) } ) ;
79+ await this . modeToken . register ( ) ;
80+
81+ this . logger . information ( `Registering token next_schedule` ) ;
82+ this . nextDateToken = new FlowToken < string > ( "next_schedule" , { type : "string" , title : __ ( "temperatures.next" ) } ) ;
83+ await this . nextDateToken . register ( ) ;
5184 }
5285}
0 commit comments