Documentation ¶
Index ¶
- Constants
- Variables
- type Controller
- func (dc *Controller) Current(ctx context.Context) (State, time.Time, bool)
- func (dc *Controller) Lock(ctx context.Context) error
- func (dc *Controller) NotifyChange(ctx context.Context, changeType, id string, sec *conf.Section) error
- func (dc *Controller) Open(ctx context.Context) error
- func (dc *Controller) Overwrite(ctx context.Context, state State, untilTime time.Time) error
- func (dc *Controller) Reset(ctx context.Context) error
- func (dc *Controller) Start() error
- func (dc *Controller) StateFor(ctx context.Context, t time.Time) (State, time.Time)
- func (dc *Controller) Stop() error
- func (dc *Controller) Unlock(ctx context.Context) error
- func (dc *Controller) Validate(ctx context.Context, sec runtime.Section) error
- type DoorConfig
- type Interfacer
- type MqttDoor
- type NoOp
- type ShellyScriptDoor
- type State
Constants ¶
const ( Locked = State("locked") Unlocked = State("unlocked") )
Possible door states.
Variables ¶
var (
AddToSchema = configBuilder.AddToSchema
)
var Spec = conf.SectionSpec{ { Name: "Type", Required: true, Default: "disabled", Description: "The type of door interface to use", Type: conf.StringType, Annotations: new(conf.Annotation).With( runtime.OneOf( runtime.PossibleValue{ Display: "MQTT", Value: "mqtt", }, runtime.PossibleValue{ Display: "Shelly Pro 2 (provided script)", Value: "shelly-script", }, runtime.PossibleValue{ Display: "Disabled", Value: "disabled", }, ), ), }, { Name: "ShellyScriptURL", Type: conf.StringType, Description: "The URL to start the provided shelly script. Used only if Type is set to Shelly Pro 2", Default: "http://localhost/scripts/1/door", }, { Name: "ConnectionName", Type: conf.StringType, Description: "The name of the MQTT connection.", Annotations: new(conf.Annotation).With( runtime.OneOfRef("MQTT", "Name", "Name"), ), }, { Name: "CommandTopic", Type: conf.StringType, Description: "The MQTT topic to publish the command to.", Default: "cliny/rpc/service/door/${command}", }, { Name: "CommandPayload", Type: conf.StringType, Description: "The payload to publish to the command topic", Default: `{"replyTo": "${responseTopic}", "command": "${command}"}`, Annotations: new(conf.Annotation).With( runtime.StringFormat("text/plain"), ), }, { Name: "ResponseTopic", Type: conf.StringType, Description: "If a response is expected, this should be set to the topic which receives the response", Default: "cliny/rpc/response/${uuid}", }, { Name: "Timeout", Type: conf.DurationType, Description: "The maximum amount of time to wait for a response.", Default: "2s", }, }
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct { *openinghours.Controller // contains filtered or unexported fields }
Controller interacts with the entry door controller via the configured interfacer and locks/unlocks the door depending on the opening hours.
func NewDoorController ¶
func NewDoorController(ctx context.Context, ohCtrl *openinghours.Controller, cs *runtime.ConfigSchema, mqttConnectionManager *mqtt.ConnectionManager) (*Controller, error)
NewDoorController returns a new door controller.
func (*Controller) Lock ¶
func (dc *Controller) Lock(ctx context.Context) error
Lock implements DoorInterfacer.
func (*Controller) NotifyChange ¶
func (*Controller) Open ¶
func (dc *Controller) Open(ctx context.Context) error
Open implements DoorInterfacer.
func (*Controller) Overwrite ¶
Overwrite overwrites the current door state with state until untilTime.
func (*Controller) Reset ¶
func (dc *Controller) Reset(ctx context.Context) error
Reset triggers a reset of the door scheduler.
func (*Controller) Start ¶
func (dc *Controller) Start() error
Start starts the scheduler for the door controller.
func (*Controller) StateFor ¶
StateFor returns the desired door state for the time t. It makes sure t is in the correct location. Like in ChangeOnDuty, the caller must make sure that t is in the desired timezone as StateFor will copy hour and date information.
func (*Controller) Stop ¶
func (dc *Controller) Stop() error
Stop requests the scheduler to stop and waits for all operations to complete.
type DoorConfig ¶ added in v1.3.0
type Interfacer ¶
type Interfacer interface { // Lock the door. Lock(context.Context) error // Unlock the door. Unlock(context.Context) error // Open the door for the next visitor to enter. Open(context.Context) error // Release is called to release and shut-down the door // interfacer. Release() }
Interfacer is used to interact and control the entry door. The door itself may be locked, unlocked or "opened". If it's state is "opened", it will lock as soon as it closes.
type MqttDoor ¶
type MqttDoor struct {
// contains filtered or unexported fields
}
MqttDoor interfaces with an door controller via mqtt. It's meant to work with github.com/tierklinik-dobersberg/door-controller.git.
func NewMqttDoor ¶
func NewMqttDoor(client *runtimeMQTT.Client, cfg DoorConfig) (*MqttDoor, error)
NewMqttDoor connects to the MQTT server configured in cfg and returns a new MqttDoor interfacer.
type ShellyScriptDoor ¶ added in v1.3.0
type ShellyScriptDoor struct {
// contains filtered or unexported fields
}
func (*ShellyScriptDoor) Lock ¶ added in v1.3.0
func (door *ShellyScriptDoor) Lock(ctx context.Context) error
func (*ShellyScriptDoor) Open ¶ added in v1.3.0
func (door *ShellyScriptDoor) Open(ctx context.Context) error
func (*ShellyScriptDoor) Release ¶ added in v1.3.0
func (*ShellyScriptDoor) Release()