// NewBridgeService - Will initiate new powerunit-io platform service. In case // of any errors we will be returning error func NewBridgeService() (service.Service, error) { var err error var cnf *config.Config if cnf, err = config.NewConfigManager(ServiceName, ServiceConfig); err != nil { return nil, fmt.Errorf("Received error while building configuration (err: %s)", err) } service := service.Service(&BridgeService{ BaseService: service.BaseService{ Logger: logger, Config: cnf, Workers: workers.NewManager(logger), Connections: connections.NewManager(logger), Devices: devices.NewManager(logger), Runtime: make(chan string), Done: make(chan bool), }, Events: make(chan events.Event), }) if err := service.Setup(); err != nil { return nil, err } return service, nil }
// NewAdapter - func NewAdapter(n string, conf map[string]interface{}, logger *logging.Logger) (Adapter, error) { cnf, err := config.NewConfigManager(n, conf) if err != nil { logger.Error("Failed to configure mqtt configuration manager for (manager: %s) (error: %s)", n, err) return nil, err } cnf.Set("name", n) return Adapter(&Connection{Logger: logger, Config: cnf}), nil }
// NewRoomWorker - func NewRoomWorker(room models.Room, floor models.Floor, c map[string]interface{}, s *BridgeService) (workers.Worker, error) { name := fmt.Sprintf("%s of %s", room.Name, floor.Name) conf, err := config.NewConfigManager(name, c) if err != nil { s.Error("Failed to configure configuration manager for (room_worker: %s) (error: %s)", name, err) return nil, err } conf.Set("name", name) return workers.Worker(&RoomWorker{ BridgeService: s, Room: room, Floor: floor, Building: s.Building, WorkerBase: workers.WorkerBase{ Config: conf, }, }), nil }