building

package
v0.0.0-...-bb3eb04 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDeviceNotFound is returned if the requested device does not exist.
	ErrDeviceNotFound = status.New(codes.NotFound, "device not found")
	// ErrNotImplemented is returned if the requested method is not yet implemented.
	ErrNotImplemented = status.New(codes.Unimplemented, "not implemented")
	// ErrInternal is returned if the requested method had an error
	ErrInternal = status.New(codes.Internal, "internal error")
)
View Source
var (
	// ErrBuildingCreateFailed is returned when creating the building failed
	ErrBuildingCreateFailed = status.New(codes.Internal, "unable to create bridge")
	// ErrFloorCreateFailed is returned when creating the floor failed
	ErrFloorCreateFailed = status.New(codes.Internal, "unable to create floor")
	// ErrRoomCreateFailed is returned when creating the room failed
	ErrRoomCreateFailed = status.New(codes.Internal, "unable to create room")
)
View Source
var (
	// ErrBuildingNotFound is returned if the requested building cannot be found
	ErrBuildingNotFound = status.New(codes.NotFound, "building not found")
	// ErrFloorNotFound is returned if the requested floor cannot be found
	ErrFloorNotFound = status.New(codes.NotFound, "floor not found")
)

Functions

This section is empty.

Types

type API

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

API is a handle to the building implementation of the device and bridge gRPC server interfaces.

func NewAPI

func NewAPI(logger *zap.Logger, svc *Service) *API

NewAPI creates a new API backed by the supplied service implementation.

func (*API) AddBuildingBridge

func (a *API) AddBuildingBridge(ctx context.Context, req *AddBridgeRequest) (*Building, error)

AddBuildingBridge satisfies the BuildingAdminService gRPC server API.

func (*API) CreateBuilding

func (a *API) CreateBuilding(ctx context.Context, req *CreateBuildingRequest) (*Building, error)

CreateBuilding satisfies the BuildingAdminService gRPC server API.

func (*API) CreateFloor

func (a *API) CreateFloor(ctx context.Context, req *CreateFloorRequest) (*Floor, error)

CreateFloor satisfies the BuildingAdminService gRPC server API.

func (*API) CreateRoom

func (a *API) CreateRoom(ctx context.Context, req *CreateRoomRequest) (*Room, error)

CreateRoom satisfies the BuildingAdminService gRPC server API.

func (*API) DeleteBuilding

func (a *API) DeleteBuilding(ctx context.Context, req *DeleteBuildingRequest) (*empty.Empty, error)

DeleteBuilding satisfies the BuildingAdminService gRPC server API.

func (*API) DeleteFloor

func (a *API) DeleteFloor(ctx context.Context, req *DeleteFloorRequest) (*empty.Empty, error)

DeleteFloor satisfies the BuildingAdminService gRPC server API.

func (*API) DeleteRoom

func (a *API) DeleteRoom(ctx context.Context, req *DeleteRoomRequest) (*empty.Empty, error)

DeleteRoom satisfies the BuildingAdminService gRPC server API.

func (*API) GetBridge

func (a *API) GetBridge(ctx context.Context, req *bridge.GetBridgeRequest) (*bridge.Bridge, error)

GetBridge retrieves the bridge profile of this domotics service.

func (*API) GetBuilding

func (a *API) GetBuilding(ctx context.Context, req *GetBuildingRequest) (*Building, error)

GetBuilding satisfies the BuildingService gRPC server API.

func (*API) GetDevice

func (a *API) GetDevice(ctx context.Context, req *bridge.GetDeviceRequest) (*bridge.Device, error)

GetDevice retrieves the specified device.

func (*API) GetFloor

func (a *API) GetFloor(ctx context.Context, req *GetFloorRequest) (*Floor, error)

GetFloor satisfies the BuildingService gRPC server API.

func (*API) ListBuildings

func (a *API) ListBuildings(ctx context.Context, req *ListBuildingsRequest) (*ListBuildingsResponse, error)

ListBuildings satisfies the BuildingService gRPC server API.

func (*API) ListDevices

ListDevices retrieves all registered devices.

func (*API) ListFloors

func (a *API) ListFloors(ctx context.Context, req *ListFloorsRequest) (*ListFloorsResponse, error)

ListFloors satisfies the BuildingService gRPC server API.

func (*API) RemoveBuildingBridge

func (a *API) RemoveBuildingBridge(ctx context.Context, req *RemoveBridgeRequest) (*Building, error)

RemoveBuildingBridge satisfies the BuildingAdminService gRPC server API.

func (*API) StreamBridgeUpdates

StreamBridgeUpdates monitors the hub and propagates any bridge change updates to registered listeners.

func (*API) StreamBuildingUpdates

func (a *API) StreamBuildingUpdates(req *StreamBuildingUpdatesRequest, stream BuildingService_StreamBuildingUpdatesServer) error

StreamBuildingUpdates satisfies the BuildingService gRPC server API.

func (*API) UpdateBuilding

func (a *API) UpdateBuilding(ctx context.Context, req *UpdateBuildingRequest) (*Building, error)

UpdateBuilding satisfies the BuildingAdminService gRPC server API.

func (*API) UpdateDeviceConfig

func (a *API) UpdateDeviceConfig(ctx context.Context, req *bridge.UpdateDeviceConfigRequest) (*bridge.Device, error)

UpdateDeviceConfig updates the specified device with the provided config.

func (*API) UpdateDeviceState

func (a *API) UpdateDeviceState(ctx context.Context, req *bridge.UpdateDeviceStateRequest) (*bridge.Device, error)

UpdateDeviceState updates the specified device with the provided state.

func (*API) UpdateFloor

func (a *API) UpdateFloor(ctx context.Context, req *UpdateFloorRequest) (*Floor, error)

UpdateFloor satisfies the BuildingAdminService gRPC server API.

func (*API) UpdateRoom

func (a *API) UpdateRoom(ctx context.Context, req *UpdateRoomRequest) (*Room, error)

UpdateRoom satisfies the BuildingAdminService gRPC server API.

type InMemoryPersister

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

InMemoryPersister satisfies the requirements of the 'StatePersister' interface in memory.

func NewInMemoryPersister

func NewInMemoryPersister() *InMemoryPersister

NewInMemoryPersister creates a new instance of an in-memory persister

func (*InMemoryPersister) Load

func (imp *InMemoryPersister) Load(ctx context.Context) (*State, error)

Load retrieves whatever is currently stored and returns it.

func (*InMemoryPersister) Persist

func (imp *InMemoryPersister) Persist(ctx context.Context, s *State) error

Persist takes the supplied state and creates a copy if it in memory for retrieval.

type SQLPersister

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

SQLPersister satisfies the requirements of the 'StatePersister' interface in a SQL DB

func NewSQLPersister

func NewSQLPersister(logger *zap.Logger, db *sql.DB) *SQLPersister

NewSQLPersister creates a new persister backed by a SQL DB

func (*SQLPersister) Load

func (p *SQLPersister) Load(ctx context.Context) (*State, error)

Load retrieves whatever is currently stored and returns it.

func (*SQLPersister) Persist

func (p *SQLPersister) Persist(ctx context.Context, s *State) error

Persist takes the supplied state and saves it to a database.

type Service

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

Service contains the active collection of buildings, rooms, floors and their associated bridges and devices. In a given instance of a domotics process it is expected there is only one active 'Service'. How does the service work? It loads its State from the supplied StatePersister For each bridge it has configured, it establishes a connection to this bridge and retrieves the current state. For each building it has configured, it builds the mappings and begins sending updates from the linked bridges and/or devices (once the bridge connection has been established). The service then accepts incoming requests to query and manipulate its state (and persists as appropriate). The service will stream updates from its configured bridges when received to registered subscribers. NOTE: clients need to perform write actions against the devices directly. The device and bridge services will be registered on the same listener but this service assumes that all updates coming from the devices/bridges are initiated independently and doesn't deal with partial write situations to simplify callflows. TODO: decide on how state syncing will happen.

func NewService

func NewService(logger *zap.Logger, persister StatePersister) *Service

NewService creates a new Service

func (*Service) AddBuilding

func (s *Service) AddBuilding(ctx context.Context, b *Building) error

AddBuilding creates a new building and persists it.

func (*Service) AddFloor

func (s *Service) AddFloor(ctx context.Context, f *Floor, bid string) error

AddFloor creates a new floor and adds it to its building, then persists it.

func (*Service) AddRoom

func (s *Service) AddRoom(ctx context.Context, r *Room, fid string) error

AddRoom creates a new room and adds it to its floor, then persists it.

func (*Service) GetBuilding

func (s *Service) GetBuilding(ctx context.Context, bid string) (*Building, error)

GetBuilding retrieves a building from the state store.

func (*Service) GetBuildings

func (s *Service) GetBuildings(ctx context.Context) ([]*Building, error)

GetBuildings retrieves all buildings from the state store.

func (*Service) GetDevice

func (s *Service) GetDevice(ctx context.Context, deviceID string) (*bridge.Device, error)

GetDevice returns the specified device, if found

func (*Service) GetDevices

func (s *Service) GetDevices(ctx context.Context) ([]*bridge.Device, error)

GetDevices returns all the devices this service is aware of

func (*Service) GetFloor

func (s *Service) GetFloor(ctx context.Context, fid string) (*Floor, error)

GetFloor retrieves a floor from the state store.

func (*Service) GetFloors

func (s *Service) GetFloors(ctx context.Context, bid string) ([]*Floor, error)

GetFloors retrieves all floors in a building from the state store.

func (*Service) Run

func (s *Service) Run()

Run listens for updates from registered endpoints and propogates them to subscribed listeners.

func (*Service) Setup

func (s *Service) Setup(ctx context.Context) error

Setup initializes the state from persistence and gets the service ready to listen for updates.

type State

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

State contains the currently active view of the state of the linked service. It (or parts of it) may be persisted to ensure recovery of the service across reboots. It may be replicated to other services, however it will always represent the currently active state of a single service.

func (*State) Dup

func (s *State) Dup() *State

Dup performs a deep copy on our state

type StatePersister

type StatePersister interface {
	Persist(context.Context, *State) error
	Load(context.Context) (*State, error)
}

StatePersister allows for the persistence and retrieval of State. The implementation of persister may choose not to persist point-in-time data (i.e. whether a light is on or off) however it should persist all configuration-related data (which devices are in which rooms).

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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