openhabtest

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventString

func EventString(e event.Event, prefix string) (string, string)

EventString returns the event topic and event string to send to the event bus

Types

type Config

type Config struct {
	// Log is sending debugging information to the test logger (t.Log(), t.Logf())
	Log Logger
	// SendEventsFromAPI will send all the events automatically on the event bus when
	// adding, updating, deleting items, things, channels, etc. from the REST API.
	// The default is off meaning the events are to be sent from the unit test
	SendEventsFromAPI bool
	// Version of the openHAB API: valid values are V2 or V3
	Version Version
}

Config is the configuration object for the mock openhab Server

type Logger

type Logger interface {
	Log(args ...interface{})
	Logf(format string, args ...interface{})
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a mock openHAB instance to use in tests.

func NewServer

func NewServer(config Config) *Server

NewServer creates a new mock openHAB instance to use in tests

func (*Server) Close

func (s *Server) Close()

Close the mock openHAB server. The call will also close any long running request to the event bus API. The method can safely be called multiple times.

func (*Server) Event

func (s *Server) Event(e event.Event)

Event sends a event.Event to the mock openHAB event bus

func (*Server) RawEvent

func (s *Server) RawEvent(topic, event string)

RawEvent sends a raw JSON string event to the event bus. Example of a raw event:

{"topic":"smarthome/items/LocalWeatherAndForecast_Current_Cloudiness/state","payload":"{\"type\":\"Quantity\",\"value\":\"20 %\"}","type":"ItemStateEvent"}

A topic parameter is needed for subscriber topic filtering, and to avoid decoding the event string unnecessarily.

func (*Server) RemoveItem

func (s *Server) RemoveItem(itemName string) error

RemoveItem removes an existing item. It doesn't return an error if the item doesn't exist.

func (*Server) SetItem

func (s *Server) SetItem(item api.Item) error

SetItem adds the new item, or replaces the existing one (with the same name). If Link property is not set, it will be automatically set

func (*Server) URL

func (s *Server) URL() string

URL returns the local URL of a mock openHAB server to use inside a unit test. The URL returned has no trailing '/'

type Version added in v0.5.0

type Version int
const (
	V2 Version = iota
	V3
)

Jump to

Keyboard shortcuts

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