github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/apis/v1/objecttypes.go (about)

     1  // Copyright 2020-2021 Ewout Prangsma
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // Author Ewout Prangsma
    16  //
    17  
    18  package v1
    19  
    20  // ObjectType identifies a type of real world objects.
    21  type ObjectType string
    22  
    23  const (
    24  	// ObjectTypeBinarySensor is the object type of a single-bit on/off sensor
    25  	ObjectTypeBinarySensor ObjectType = "binary-sensor"
    26  	// ObjectTypeBinaryOutput is the object type of a single-bit on/off output
    27  	ObjectTypeBinaryOutput ObjectType = "binary-output"
    28  	// ObjectTypeMagneticSwitch is the object type of switch that a single magnetic coil per direction.
    29  	// The coil has to stay activated.
    30  	ObjectTypeMagneticSwitch ObjectType = "magnetic-switch"
    31  	// ObjectTypeServoSwitch is the object type of a servo driven switch, with an option phase switching relay.
    32  	ObjectTypeServoSwitch ObjectType = "servo-switch"
    33  	// ObjectTypeRelaySwitch is the object type of a double relay driven switch, with an option phase switching relay.
    34  	ObjectTypeRelaySwitch ObjectType = "relay-switch"
    35  	// ObjectTypeTrackInverter is the object type of a four relay based track power inverter.
    36  	ObjectTypeTrackInverter ObjectType = "track-inverter"
    37  )
    38  
    39  // ExpectedConnections returns the connection names that are expected for an object
    40  // of given type.
    41  // Returns: Required connections, Optional connections
    42  func (ot ObjectType) ExpectedConnections() ([]ConnectionName, []ConnectionName) {
    43  	switch ot {
    44  	case ObjectTypeBinarySensor:
    45  		return []ConnectionName{ConnectionNameSensor}, nil
    46  	case ObjectTypeBinaryOutput:
    47  		return []ConnectionName{ConnectionNameOutput}, nil
    48  	case ObjectTypeMagneticSwitch:
    49  		return []ConnectionName{ConnectionNameMagneticStraightA, ConnectionNameMagneticStraightB, ConnectionNameMagneticOffA, ConnectionNameMagneticOffB}, nil
    50  	case ObjectTypeServoSwitch:
    51  		return []ConnectionName{ConnectionNameServo}, []ConnectionName{ConnectionNamePhaseStraightRelay, ConnectionNamePhaseOffRelay}
    52  	case ObjectTypeRelaySwitch:
    53  		return []ConnectionName{ConnectionNameStraightRelay, ConnectionNameOffRelay}, nil
    54  	case ObjectTypeTrackInverter:
    55  		return []ConnectionName{ConnectionNameRelayOutAInA, ConnectionNameRelayOutBInA, ConnectionNameRelayOutAInB, ConnectionNameRelayOutBInB}, nil
    56  	default:
    57  		return nil, nil
    58  	}
    59  }
    60  
    61  // ExpectedConfigurations returns the possible configuration keys that are supported
    62  // for an object of given type.
    63  // Returns: Supported configuration keys
    64  func (ot ObjectType) ExpectedConfigurations() []ObjectConfigKey {
    65  	switch ot {
    66  	case ObjectTypeBinarySensor:
    67  		return []ObjectConfigKey{
    68  			ObjectConfigKeyDebug,
    69  		}
    70  	case ObjectTypeBinaryOutput:
    71  		return []ObjectConfigKey{
    72  			ObjectConfigKeyDebug,
    73  		}
    74  	case ObjectTypeMagneticSwitch:
    75  		return []ObjectConfigKey{
    76  			ObjectConfigKeyDebug,
    77  			ObjectConfigKeyMagneticAlwaysEnabled,
    78  			ObjectConfigKeyMagneticStraightInvert,
    79  			ObjectConfigKeyMagneticOffInvert,
    80  		}
    81  	case ObjectTypeServoSwitch:
    82  		return []ObjectConfigKey{
    83  			ObjectConfigKeyDebug,
    84  		}
    85  	case ObjectTypeRelaySwitch:
    86  		return []ObjectConfigKey{
    87  			ObjectConfigKeyDebug,
    88  		}
    89  	case ObjectTypeTrackInverter:
    90  		return []ObjectConfigKey{
    91  			ObjectConfigKeyDebug,
    92  		}
    93  	default:
    94  		return nil
    95  	}
    96  }
    97  
    98  // AllObjectTypes returns all possible object types.
    99  func AllObjectTypes() []ObjectType {
   100  	return []ObjectType{ObjectTypeBinarySensor, ObjectTypeBinaryOutput, ObjectTypeMagneticSwitch, ObjectTypeServoSwitch, ObjectTypeRelaySwitch, ObjectTypeTrackInverter}
   101  }