43 lines
756 B
Go
43 lines
756 B
Go
package main
|
|
|
|
type SwitchDevice struct {
|
|
baseDevice *Device
|
|
}
|
|
|
|
// init
|
|
func createSwitchDevice(device *Device) *SwitchDevice {
|
|
device.typeID = 1
|
|
return &SwitchDevice{baseDevice: device}
|
|
}
|
|
|
|
//states:
|
|
//0: unknown
|
|
//1: on
|
|
//2: off
|
|
|
|
func (switchDevice *SwitchDevice) on() error {
|
|
if switchDevice.baseDevice.channels[0] != 1 {
|
|
return switchDevice.baseDevice.setChannel(0, 1)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (switchDevice *SwitchDevice) off() error {
|
|
if switchDevice.baseDevice.channels[0] != 2 {
|
|
return switchDevice.baseDevice.setChannel(0, 2)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (switchDevice *SwitchDevice) getStringState() string {
|
|
switch switchDevice.baseDevice.channels[0] {
|
|
case 1:
|
|
return "On"
|
|
case 2:
|
|
return "Off"
|
|
}
|
|
return "Unknown"
|
|
}
|