49 lines
906 B
Go
49 lines
906 B
Go
|
package main
|
||
|
|
||
|
type GateDevice struct {
|
||
|
baseDevice *Device
|
||
|
}
|
||
|
|
||
|
// init
|
||
|
func createGateDevice(device *Device) *GateDevice {
|
||
|
device.typeID = 3
|
||
|
return &GateDevice{baseDevice: device}
|
||
|
}
|
||
|
|
||
|
//states:
|
||
|
//0: unknown
|
||
|
//1: closed
|
||
|
//2: closing
|
||
|
//3: opening
|
||
|
//4: open
|
||
|
|
||
|
func (gateDevice *GateDevice) open() error {
|
||
|
if gateDevice.baseDevice.channels[0] != 3 && gateDevice.baseDevice.channels[1] != 4 {
|
||
|
return gateDevice.baseDevice.setChannel(0, 3)
|
||
|
} else {
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (gateDevice *GateDevice) close() error {
|
||
|
if gateDevice.baseDevice.channels[0] != 1 && gateDevice.baseDevice.channels[1] != 2 {
|
||
|
return gateDevice.baseDevice.setChannel(0, 2)
|
||
|
} else {
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (gateDevice *GateDevice) getStringState() string {
|
||
|
switch gateDevice.baseDevice.channels[0] {
|
||
|
case 1:
|
||
|
return "Closed"
|
||
|
case 2:
|
||
|
return "Closing"
|
||
|
case 3:
|
||
|
return "Opening"
|
||
|
case 4:
|
||
|
return "Open"
|
||
|
}
|
||
|
return "Unknown"
|
||
|
}
|