Skip to content

Commit eec4eba

Browse files
committed
Attributes for SmartFan is no longer defined and support circulators
1 parent 8e1e2e5 commit eec4eba

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

device.go

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ type DeviceStatus struct {
144144
IsGrouped bool `json:"group"`
145145
IsMoving bool `json:"moving"`
146146
SlidePosition int `json:"slidePosition"`
147-
FanMode int `json:"mode"`
148-
FanSpeed int `json:"speed"`
149-
IsShaking bool `json:"shaking"`
150-
ShakeCenter int `json:"shakeCenter"`
151-
ShakeRange int `json:"shakeRange"`
152147
IsMoveDetected bool `json:"moveDetected"`
153148
Brightness BrightnessState `json:"brightness"`
154149
LightLevel int `json:"lightLevel"`
@@ -168,6 +163,12 @@ type DeviceStatus struct {
168163
Version DeviceVersion `json:"version"`
169164
Direction string `json:"direction"`
170165
CO2 int `json:"CO2"`
166+
Mode Mode `json:"mode"`
167+
NightStatus NightStatus `json:"nightStatus"`
168+
Oscillation OscillationStatus `json:"oscillation"`
169+
VerticalOscillation OscillationStatus `json:"verticalOscillation"`
170+
ChargingStatus ChargingStatus `json:"chargingStatus"`
171+
FanSpeed int `json:"fanSpeed"`
171172
}
172173

173174
type PowerState string
@@ -259,6 +260,68 @@ const (
259260
CleanerInDustCollecting CleanerWorkingStatus = "InDustCollecting"
260261
)
261262

263+
type Mode struct {
264+
circulatorMode CirculatorMode
265+
intMode int // evaporative humidifier or air purifier
266+
}
267+
268+
func (mode *Mode) UnmarshalJSON(b []byte) error {
269+
var iv int
270+
if err := json.Unmarshal(b, &iv); err != nil {
271+
var sv string
272+
if err := json.Unmarshal(b, &sv); err != nil {
273+
return fmt.Errorf("cannot unmarshal to both of int and string: %w", err)
274+
}
275+
276+
mode.circulatorMode = CirculatorMode(sv)
277+
278+
return nil
279+
}
280+
281+
mode.intMode = iv
282+
283+
return nil
284+
}
285+
286+
func (mode Mode) CirculatorMode() (CirculatorMode, error) {
287+
if mode.circulatorMode != "" {
288+
return mode.circulatorMode, nil
289+
}
290+
291+
return "", errors.New("circulator mode is only available for circulator and battery circulator")
292+
}
293+
294+
type CirculatorMode string
295+
296+
const (
297+
CirculatorModeDirect CirculatorMode = "direct"
298+
CirculatorModeNatural CirculatorMode = "natural"
299+
CirculatorModeSleep CirculatorMode = "sleep"
300+
CirculatorModeUltraQuitet CirculatorMode = "baby"
301+
)
302+
303+
type NightStatus string
304+
305+
const (
306+
NightStatusOff NightStatus = "off"
307+
NightStatusMode1 NightStatus = "1"
308+
NightStatusMode2 NightStatus = "2"
309+
)
310+
311+
type OscillationStatus string
312+
313+
const (
314+
OscillationStatusOn OscillationStatus = "on"
315+
OscillationStatusOff OscillationStatus = "off"
316+
)
317+
318+
type ChargingStatus string
319+
320+
const (
321+
ChargingStatusCharging ChargingStatus = "charging"
322+
ChargingStatusUncharged ChargingStatus = "uncharged"
323+
)
324+
262325
// Status get the status of a physical device that has been added to the current
263326
// user's account. Physical devices refer to the SwitchBot products.
264327
// The first given argument `id` is a device ID which can be retrieved by

switchbot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ const (
110110
MeterPro PhysicalDeviceType = "MeterPro"
111111
// MeterPro(CO2) is SwitchBot CO2 Sensor Model No. W4900010
112112
MeterProCO2 PhysicalDeviceType = "MeterPro(CO2)"
113+
// Circulator Fan is SwitchBot Circulator Fan Model No. W3800511
114+
CirculatorFan PhysicalDeviceType = "Circulator Fan"
115+
// Battery Circulator Fan is SwitchBot Battery Circulator Fan Model No. W3800510
116+
BatteryCirculatorFan PhysicalDeviceType = "Battery Circulator Fan"
113117
)
114118

115119
type VirtualDeviceType string

0 commit comments

Comments
 (0)