Skip to content

Commit ed80c19

Browse files
committed
fix: manual control options
1 parent e14064d commit ed80c19

File tree

3 files changed

+36
-104
lines changed

3 files changed

+36
-104
lines changed

src/tadox.ts

+19-97
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import type {
2-
ACMode,
3-
DeepPartial,
4-
FanLevel,
5-
FanSpeed,
6-
HorizontalSwing,
72
Power,
8-
Termination,
9-
VerticalSwing,
103
XFeatures,
4+
XOverlay,
115
XQuickAction,
126
XRoom,
137
XRoomsAndDevices,
14-
XRoomSetting,
15-
ZoneOverlayTermination,
8+
XTermination,
169
} from "./types";
1710

1811
import { Method } from "axios";
@@ -85,7 +78,7 @@ export class TadoX extends Tado {
8578
* @returns A promise that resolves on completion.
8679
*/
8780
async performQuickAction(home_id: number, action: XQuickAction): Promise<string> {
88-
return this.apiCallX(`/homes/${home_id}/quickActions/${action}`);
81+
return this.apiCallX(`/homes/${home_id}/quickActions/${action}`, "POST");
8982
}
9083

9184
/**
@@ -106,114 +99,43 @@ export class TadoX extends Tado {
10699
* @param room_id - The identifier of the room within the home.
107100
* @param power - The power state, either 'ON' or 'OFF'.
108101
* @param temperature - The desired temperature for the overlay, in celsius.
109-
* @param termination - The termination condition for the overlay. Options include 'MANUAL', 'AUTO', 'NEXT_TIME_BLOCK', or a number representing duration in seconds.
110-
* @param fan_speed - The desired fan speed or level.
111-
* @param ac_mode - The air conditioning mode (e.g., 'COOL', 'HEAT').
112-
* @param verticalSwing - The vertical swing setting for air conditioning.
113-
* @param horizontalSwing - The horizontal swing setting for air conditioning.
102+
* @param termination - The termination condition for the overlay. Options include 'MANUAL', 'NEXT_TIME_BLOCK', or a number representing duration in seconds.
114103
* @returns A promise that resolves to the created zone overlay.
115104
*/
116105
async manualControl(
117106
home_id: number,
118107
room_id: number,
119108
power: Power,
120-
temperature?: number,
121-
termination?: Termination | undefined | number,
122-
fan_speed?: FanSpeed | FanLevel,
123-
ac_mode?: ACMode,
124-
verticalSwing?: VerticalSwing,
125-
horizontalSwing?: HorizontalSwing,
109+
temperature: number,
110+
termination: XTermination | number,
126111
): Promise<unknown> {
127-
// NOTE: If you update this code please also update `setZoneOverlay` in `tado.js`
128-
const room_state = await this.getRoomState(home_id, room_id);
129-
130-
const config: {
131-
setting: DeepPartial<XRoomSetting>;
132-
termination?: Partial<ZoneOverlayTermination>;
133-
type: "MANUAL";
134-
} = {
112+
const overlay: XOverlay = {
135113
setting: {
136-
type: room_state.setting.type,
114+
power,
115+
temperature: {
116+
value: temperature,
117+
},
118+
},
119+
termination: {
120+
type: "MANUAL",
137121
},
138-
type: "MANUAL",
139122
};
140123

141-
if (power.toUpperCase() == "ON") {
142-
config.setting.power = "ON";
143-
144-
if (
145-
(config.setting.type == "HEATING" || config.setting.type == "HOT_WATER") &&
146-
temperature
147-
) {
148-
config.setting.temperature = { value: temperature };
149-
}
150-
151-
if (room_state.setting.type == "AIR_CONDITIONING") {
152-
if (ac_mode) {
153-
config.setting.mode = ac_mode.toUpperCase() as ACMode;
154-
}
155-
156-
if (verticalSwing) {
157-
config.setting.verticalSwing = verticalSwing;
158-
}
159-
160-
if (horizontalSwing) {
161-
config.setting.horizontalSwing = horizontalSwing;
162-
}
163-
164-
if (
165-
config.setting.mode?.toLowerCase() == "heat" ||
166-
config.setting.mode?.toLowerCase() == "cool" ||
167-
config.setting.mode?.toLowerCase() == "auto" ||
168-
config.setting.mode?.toLowerCase() == "dry"
169-
) {
170-
if (temperature) {
171-
config.setting.temperature = { value: temperature };
172-
}
173-
174-
if (fan_speed && config.setting.mode?.toLowerCase() != "dry") {
175-
if (room_state.setting.fanLevel !== undefined) {
176-
config.setting.fanLevel = fan_speed.toUpperCase() as FanLevel;
177-
} else {
178-
config.setting.fanSpeed = fan_speed.toUpperCase() as FanSpeed;
179-
}
180-
}
181-
}
182-
}
183-
} else {
184-
config.setting.power = "OFF";
185-
}
186-
187-
if (!termination) {
188-
termination = "MANUAL";
189-
}
190-
191124
if (typeof termination === "string" && !isNaN(parseInt(termination))) {
192125
termination = parseInt(termination);
193126
}
194127

195128
if (typeof termination === "number") {
196-
config.type = "MANUAL";
197-
config.termination = {
198-
typeSkillBasedApp: "TIMER",
129+
overlay.termination = {
130+
type: "TIMER",
199131
durationInSeconds: termination,
200132
};
201-
} else if (termination.toLowerCase() == "manual") {
202-
config.type = "MANUAL";
203-
config.termination = {
204-
typeSkillBasedApp: "MANUAL",
205-
};
206-
} else if (termination.toLowerCase() == "auto") {
207-
config.termination = {
208-
type: "TADO_MODE",
209-
};
210133
} else if (termination.toLowerCase() == "next_time_block") {
211-
config.type = "MANUAL";
212-
config.termination = {
213-
typeSkillBasedApp: "NEXT_TIME_BLOCK",
134+
overlay.termination = {
135+
type: "NEXT_TIME_BLOCK",
214136
};
215137
}
216138

217-
return this.apiCallX(`/homes/${home_id}/rooms/${room_id}/manualControl`, "post", config);
139+
return this.apiCallX(`/homes/${home_id}/rooms/${room_id}/manualControl`, "post", overlay);
218140
}
219141
}

src/types/enums.ts

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type ACHorizontalSwing = "RIGHT" | "MID" | "LEFT" | "ON" | "MID_RIGHT" |
2828

2929
export type Termination = "AUTO" | "NEXT_TIME_BLOCK" | "MANUAL";
3030

31+
export type XTermination = "NEXT_TIME_BLOCK" | "MANUAL";
32+
3133
export type OutdoorQualityLevel = "EXCELLENT" | "NONE";
3234

3335
export type WeatherStateValue =

src/types/index.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -992,13 +992,6 @@ export type XRoomSensorDataPoints = {
992992
export type XRoomSetting = {
993993
power: Power;
994994
temperature: XRoomValue;
995-
// No idea if the below are supposed to be here or not
996-
type?: ZoneType;
997-
mode?: ACMode;
998-
verticalSwing?: VerticalSwing;
999-
horizontalSwing?: HorizontalSwing;
1000-
fanSpeed?: FanSpeed;
1001-
fanLevel?: FanLevel;
1002995
};
1003996

1004997
export type XNextScheduleChange = {
@@ -1064,3 +1057,18 @@ export type XRoomsAndDevices = {
10641057
export type XFeatures = {
10651058
availableFeatures: XFeature[];
10661059
};
1060+
1061+
export type XTerminationConfig =
1062+
| {
1063+
type: "NEXT_TIME_BLOCK" | "MANUAL";
1064+
}
1065+
| {
1066+
type: "TIMER";
1067+
durationInSeconds: number;
1068+
};
1069+
1070+
export type XOverlay = {
1071+
setting: XRoomSetting;
1072+
termination: XTerminationConfig;
1073+
isBoost?: boolean;
1074+
};

0 commit comments

Comments
 (0)