casa

package module
v0.0.0-...-5229af2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2016 License: Apache-2.0 Imports: 1 Imported by: 4

README

Release Travis Coverage Status GoDoc Go Report Card

Random notes for now...

Casa is designed to be as flexible as possible. That is why this package is nothing but type definitions, and everything that Casa can do is done through external service "plugins".

The cmd/casa sub-package is the default server, and it uses three plugins right now: mqtt, logger, and hue. When run it starts an MQTT broker, uses the logger to print out all received messages, and starts the hue service to connect to a hue bridge. You'll need to know the bridge IP and have a user name already generated. This will be automated in the future.

  • Casa starts an MQTT broker on port 1883 with ZERO security. It is possible to enable TLS, just adjust the config and generate a certificate and a key. Support for letsencrypt automatic certificates is being worked on.

  • Each service communicates with the MQTT broker via localhost:1883.

  • We should also add the ability to use an external MQTT broker if desired.

  • Use the github.com/pkg/errors package for returning errors where possible. It's very handy and provides a nice stack trace if we want it.

  • github.com/spf13/viper is used for handling configuration. Each service has it's own section in the config file, and that section is passed to the service when it is started.

  • github.com/spf13/cobra is used to handle the casa program commands. Right now there is just a command to start the server and print the version. More should be added, like the ability to generate a default config file on demand.

  • There is an environment package that cmd/casa uses to store global configuration and state. This makes using a single logger easier, as well as giving somewhere the plugins can register themselves to.

Documentation

Overview

Package casa defines interfaces and types for the casa home automation platform. These interfaces are subject to change without notice as casa is refined. Feel free to play with it now but wait until a v1 release before you depend on it for anything.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Log(a ...interface{})
}

Logger represents a way to log error messages for the user.

type Message

type Message struct {
	Topic   string
	Payload []byte
	Retain  bool
}

Message represents an MQTT message Might be better to be an interface?

type MessageBus

type MessageBus interface {
	// Shutdown the MessageBus
	Close() error

	// NewClient returns a client that is connected to the MessageBus
	NewClient() MessageClient
}

MessageBus defines a system for passing Messages

type MessageClient

type MessageClient interface {
	// Register a function to call when a message or error is received
	Handle(func(msg *Message, err error))

	// Publish a pre-composed message
	PublishMessage(message Message) error

	// Subscribes to the given topic
	Subscribe(topic string) error

	// Removes subscription for the topic
	Unsubscribe(topic string) error

	// Closes the client
	Close() error
}

MessageClient sends and receives Messages to a MessageBus

type Service

type Service interface {
	// Start the service. Config is the config section for that service,
	// with the global MQTT config section appended.
	Start(config *viper.Viper) error

	// Specifies the logger to be used.
	UseLogger(logger Logger)

	// Stops the service.
	Stop() error
}

Service defines a type that can subscribe to the message bus and perform actions.

Directories

Path Synopsis
cmd
casa/environment
The environment package provides a way to setup a global environment and also have the ability to create local encironments for testing.
The environment package provides a way to setup a global environment and also have the ability to create local encironments for testing.

Jump to

Keyboard shortcuts

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