door

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Locked   = State("locked")
	Unlocked = State("unlocked")
)

Possible door states.

Variables

View Source
var (
	AddToSchema = configBuilder.AddToSchema
)
View Source
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) Current

func (dc *Controller) Current(ctx context.Context) (State, time.Time, bool)

Current returns the current door state.

func (*Controller) Lock

func (dc *Controller) Lock(ctx context.Context) error

Lock implements DoorInterfacer.

func (*Controller) NotifyChange

func (dc *Controller) NotifyChange(ctx context.Context, changeType, id string, sec *conf.Section) error

func (*Controller) Open

func (dc *Controller) Open(ctx context.Context) error

Open implements DoorInterfacer.

func (*Controller) Overwrite

func (dc *Controller) Overwrite(ctx context.Context, state State, untilTime time.Time) error

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

func (dc *Controller) StateFor(ctx context.Context, t time.Time) (State, time.Time)

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.

func (*Controller) Unlock

func (dc *Controller) Unlock(ctx context.Context) error

Unlock implements DoorInterfacer.

func (*Controller) Validate

func (dc *Controller) Validate(ctx context.Context, sec runtime.Section) error

type DoorConfig added in v1.3.0

type DoorConfig struct {
	Type            string
	ShellyScriptURL string
	ConnectionName  string
	CommandTopic    string
	CommandPayload  string
	ResponseTopic   string
	Timeout         time.Duration
}

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.

func (*MqttDoor) Client

func (door *MqttDoor) Client() mqtt.Client

Client returns the MQTT client used.

func (*MqttDoor) Lock

func (door *MqttDoor) Lock(ctx context.Context) error

Lock send a lock request.

func (*MqttDoor) Open

func (door *MqttDoor) Open(ctx context.Context) error

Open sends an open request.

func (*MqttDoor) Release

func (door *MqttDoor) Release()

Release releases resources of the door interfacer.

func (*MqttDoor) Unlock

func (door *MqttDoor) Unlock(ctx context.Context) error

Unlock sends an unlock request.

type NoOp

type NoOp struct{}

func (NoOp) Lock

func (NoOp) Lock(context.Context) error

func (NoOp) Open

func (NoOp) Open(context.Context) error

func (NoOp) Release

func (NoOp) Release()

func (NoOp) Unlock

func (NoOp) Unlock(context.Context) error

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()

func (*ShellyScriptDoor) Unlock added in v1.3.0

func (door *ShellyScriptDoor) Unlock(ctx context.Context) error

type State

type State string

State describes the current state of the entry door.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL