Skip to content

Commit

Permalink
More comments, small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
splattner committed Sep 27, 2023
1 parent 1a31f15 commit 5786031
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This client currently implements a [`MediaPlayer` entity](https://github.com/unf

Run with `ucrt deconz`

This client currently implements [`Light` entities](https://github.com/unfoldedcircle/core-api/blob/main/doc/entities/entity_light.md) for discovered DeCONZ Lights and [`Sensor` entitites](https://github.com/unfoldedcircle/core-api/blob/main/doc/entities/entity_sensor.md) for selected DeCONZ sensors.
This client currently implements [`Light` entities](https://github.com/unfoldedcircle/core-api/blob/main/doc/entities/entity_light.md) for discovered DeCONZ Lights and Groups and [`Sensor` entitites](https://github.com/unfoldedcircle/core-api/blob/main/doc/entities/entity_sensor.md) for selected DeCONZ sensors.

## How to use

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Client struct {
// Here you can add entities if they are already known
initFunc func()
// Called by RemoteTwo when the integration is added and setup started
setupFunc func()
setupFunc func(integration.SetupData)
// Handles connect/disconnect calls from RemoteTwo
clientLoopFunc func()
setDriverUserDataFunc func(map[string]string, bool)
Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *Client) HandleConnection(e *integration.ConnectEvent) {
func (c *Client) HandleSetup(setup_data integration.SetupData) {

if c.setupFunc != nil {
c.setupFunc()
c.setupFunc(setup_data)
}

}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/deconzclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *DeconzClient) initDeconzClient() {

}

func (c *DeconzClient) deconzHandleSetup() {
func (c *DeconzClient) deconzHandleSetup(setup_data integration.SetupData) {
//event_type: SETUP with state: SETUP is a progress event to keep the process running,
// If the setup process takes more than a few seconds,
// the integration should send driver_setup_change events with state: SETUP to the Remote Two
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/denonavrclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *DenonAVRClient) initDenonAVRClient() {

}

func (c *DenonAVRClient) denonHandleSetup() {
func (c *DenonAVRClient) denonHandleSetup(setup_data integration.SetupData) {
//event_type: SETUP with state: SETUP is a progress event to keep the process running,
// If the setup process takes more than a few seconds,
// the integration should send driver_setup_change events with state: SETUP to the Remote Two
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/deconz/deconz.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewCommand(rootCmd *cobra.Command) *cobra.Command {

var command = &cobra.Command{
Use: "deconz",
Short: "Deconz",
Short: "Start Deconz Ingegration",
Long: "Deconz Integration for a Unfolded Circle Remote Two",
Run: func(c *cobra.Command, args []string) {

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/denonavr/denonavr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewCommand(rootCmd *cobra.Command) *cobra.Command {

var command = &cobra.Command{
Use: "denonavr",
Short: "Denon AVR",
Short: "Start Denon AVR Ingegration",
Long: "Denon AVR Integration for a Unfolded Circle Remote Two",
Run: func(c *cobra.Command, args []string) {

Expand Down
2 changes: 2 additions & 0 deletions pkg/entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
UnkownEntityState = "UNKNOWN"
)

// Generic Remote Two Entity
// See https://github.com/unfoldedcircle/core-api/blob/main/doc/entities/README.md for details
type Entity struct {
Id string `json:"entity_id"`
EntityType
Expand Down
5 changes: 3 additions & 2 deletions pkg/integration/advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"github.com/grandcat/zeroconf"
)

// TODO: not working?
// Start Advertising the integration with mDNS
func (i *Integration) startAdvertising() {
log.Info("Start advertising UC Integration with mDNS")

txt := []string{
"name=" + i.Metadata.Name.En,
"developer=" + i.Metadata.Developer.Name,
"ver=" + i.Metadata.Version,
"ws_path=/ws",
"ws_path=" + i.Config["websocketPath"].(string),
}

server, err := zeroconf.Register(i.Metadata.DriverId, "_uc-integration._tcp", "local.", i.Config["listenport"].(int), txt, nil)
Expand All @@ -25,6 +25,7 @@ func (i *Integration) startAdvertising() {
i.mdns = server
}

// Stop mDNS advertisement
func (i *Integration) stopAdvertising() {
if i.mdns != nil {
log.Info("Stop advertising UC Integration")
Expand Down
1 change: 1 addition & 0 deletions pkg/integration/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package integration

// Generic string key/value config map to store configuration option
type Config map[string]interface{}
3 changes: 3 additions & 0 deletions pkg/integration/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func (i *Integration) handleCommand(entity interface{}, req *EntityCommandReq) i

case *entities.CoverEntity:
return e.HandleCommand(cmd_id, params)

case *entities.SensorEntity:
// Sensor do not have commands
}

return 404
Expand Down
1 change: 1 addition & 0 deletions pkg/integration/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (i *Integration) sendEventMessage(res *interface{}, messageType int) error

}

// Handle events received from the Remote
func (i *Integration) handleEvent(req *RequestMessage, p []byte) interface{} {

var res interface{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (i *Integration) SetHandleSetDriverUserDataFunction(f func(map[string]strin
i.handleSetDriverUserDataFunction = f
}

// Send the Driver Setup State to Remote two
// Set and then Send the Driver Setup State to Remote two
func (i *Integration) SetDriverSetupState(event_Type DriverSetupEventType, state DriverSetupState, err DriverSetupError, requireUserAction *RequireUserAction) {

log.WithFields(log.Fields{
Expand Down
4 changes: 2 additions & 2 deletions pkg/integration/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (i *Integration) wsEndpoint(w http.ResponseWriter, r *http.Request) {
}

func (i *Integration) wsReader(ws *websocket.Conn) {
log.Debug("Start Websocket read loop")
log.WithField("RemoteAddr", ws.RemoteAddr().String()).Debug("Start Websocket read loop")
ws.SetReadLimit(maxMessageSize)
ws.SetReadDeadline(time.Now().Add(pongWait))
ws.SetPongHandler(func(string) error {
Expand Down Expand Up @@ -102,7 +102,7 @@ func (i *Integration) wsReader(ws *websocket.Conn) {
}

func (i *Integration) wsWriter(ws *websocket.Conn) {
log.Debug("Start Websocket write loop")
log.WithField("RemoteAddr", ws.RemoteAddr().String()).Debug("Start Websocket write loop")
ticker := time.NewTicker(pingPeriod)

defer func() {
Expand Down

0 comments on commit 5786031

Please sign in to comment.