Documentation ¶
Index ¶
- Variables
- type API
- func (a *API) AddBuildingBridge(ctx context.Context, req *AddBridgeRequest) (*Building, error)
- func (a *API) CreateBuilding(ctx context.Context, req *CreateBuildingRequest) (*Building, error)
- func (a *API) CreateFloor(ctx context.Context, req *CreateFloorRequest) (*Floor, error)
- func (a *API) CreateRoom(ctx context.Context, req *CreateRoomRequest) (*Room, error)
- func (a *API) DeleteBuilding(ctx context.Context, req *DeleteBuildingRequest) (*empty.Empty, error)
- func (a *API) DeleteFloor(ctx context.Context, req *DeleteFloorRequest) (*empty.Empty, error)
- func (a *API) DeleteRoom(ctx context.Context, req *DeleteRoomRequest) (*empty.Empty, error)
- func (a *API) GetBridge(ctx context.Context, req *bridge.GetBridgeRequest) (*bridge.Bridge, error)
- func (a *API) GetBuilding(ctx context.Context, req *GetBuildingRequest) (*Building, error)
- func (a *API) GetDevice(ctx context.Context, req *bridge.GetDeviceRequest) (*bridge.Device, error)
- func (a *API) GetFloor(ctx context.Context, req *GetFloorRequest) (*Floor, error)
- func (a *API) ListBuildings(ctx context.Context, req *ListBuildingsRequest) (*ListBuildingsResponse, error)
- func (a *API) ListDevices(ctx context.Context, req *bridge.ListDevicesRequest) (*bridge.ListDevicesResponse, error)
- func (a *API) ListFloors(ctx context.Context, req *ListFloorsRequest) (*ListFloorsResponse, error)
- func (a *API) RemoveBuildingBridge(ctx context.Context, req *RemoveBridgeRequest) (*Building, error)
- func (a *API) StreamBridgeUpdates(req *bridge.StreamBridgeUpdatesRequest, ...) error
- func (a *API) StreamBuildingUpdates(req *StreamBuildingUpdatesRequest, ...) error
- func (a *API) UpdateBuilding(ctx context.Context, req *UpdateBuildingRequest) (*Building, error)
- func (a *API) UpdateDeviceConfig(ctx context.Context, req *bridge.UpdateDeviceConfigRequest) (*bridge.Device, error)
- func (a *API) UpdateDeviceState(ctx context.Context, req *bridge.UpdateDeviceStateRequest) (*bridge.Device, error)
- func (a *API) UpdateFloor(ctx context.Context, req *UpdateFloorRequest) (*Floor, error)
- func (a *API) UpdateRoom(ctx context.Context, req *UpdateRoomRequest) (*Room, error)
- type InMemoryPersister
- type SQLPersister
- type Service
- func (s *Service) AddBuilding(ctx context.Context, b *Building) error
- func (s *Service) AddFloor(ctx context.Context, f *Floor, bid string) error
- func (s *Service) AddRoom(ctx context.Context, r *Room, fid string) error
- func (s *Service) GetBuilding(ctx context.Context, bid string) (*Building, error)
- func (s *Service) GetBuildings(ctx context.Context) ([]*Building, error)
- func (s *Service) GetDevice(ctx context.Context, deviceID string) (*bridge.Device, error)
- func (s *Service) GetDevices(ctx context.Context) ([]*bridge.Device, error)
- func (s *Service) GetFloor(ctx context.Context, fid string) (*Floor, error)
- func (s *Service) GetFloors(ctx context.Context, bid string) ([]*Floor, error)
- func (s *Service) Run()
- func (s *Service) Setup(ctx context.Context) error
- type State
- type StatePersister
Constants ¶
This section is empty.
Variables ¶
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") )
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") )
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 (*API) AddBuildingBridge ¶
AddBuildingBridge satisfies the BuildingAdminService gRPC server API.
func (*API) CreateBuilding ¶
CreateBuilding satisfies the BuildingAdminService gRPC server API.
func (*API) CreateFloor ¶
CreateFloor satisfies the BuildingAdminService gRPC server API.
func (*API) CreateRoom ¶
CreateRoom satisfies the BuildingAdminService gRPC server API.
func (*API) DeleteBuilding ¶
DeleteBuilding satisfies the BuildingAdminService gRPC server API.
func (*API) DeleteFloor ¶
DeleteFloor satisfies the BuildingAdminService gRPC server API.
func (*API) DeleteRoom ¶
DeleteRoom satisfies the BuildingAdminService gRPC server API.
func (*API) GetBuilding ¶
GetBuilding 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 ¶
func (a *API) ListDevices(ctx context.Context, req *bridge.ListDevicesRequest) (*bridge.ListDevicesResponse, error)
ListDevices retrieves all registered devices.
func (*API) ListFloors ¶
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 ¶
func (a *API) StreamBridgeUpdates(req *bridge.StreamBridgeUpdatesRequest, stream bridge.BridgeService_StreamBridgeUpdatesServer) error
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 ¶
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 ¶
UpdateFloor 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
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
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 ¶
AddBuilding creates a new building and persists it.
func (*Service) AddFloor ¶
AddFloor creates a new floor and adds it to its building, then persists it.
func (*Service) GetBuilding ¶
GetBuilding retrieves a building from the state store.
func (*Service) GetBuildings ¶
GetBuildings retrieves all buildings from the state store.
func (*Service) GetDevices ¶
GetDevices returns all the devices this service is aware of
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.
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).