Skip to content

Commit

Permalink
Add new endpoint to DigitalStrom Client
Browse files Browse the repository at this point in the history
  • Loading branch information
albertomontesg committed May 22, 2022
1 parent b12ffbc commit f509edb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/digitalstrom/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ type DeviceGetOutputChannelValueResponse struct {
Channels []ChannelValue `mapstructure:"channels"`
}

type DeviceGetMaxMotionTimeResponse struct {
Supported bool `mapstructure:"supported"`
Value int64 `mapstructure:"value"`
}

type CircuitGetConsumptionResponse struct {
Consumption float64 `mapstructure:"consumption"`
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/digitalstrom/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type Client interface {
DeviceGetOutputChannelValue(dsid string, channels []string) (*DeviceGetOutputChannelValueResponse, error)
// Sets the values for the channels in the given device.
DeviceSetOutputChannelValue(dsid string, channelValues map[string]int) error
// Gets the motion time for the device.
DeviceGetMaxMotionTime(dsid string) (*DeviceGetMaxMotionTimeResponse, error)
// Subscribe to an event and run the given callback when an event of the
// given types is received.
EventSubscribe(event EventType, eventCallback EventCallback) error
Expand Down Expand Up @@ -271,6 +273,13 @@ func (c *client) DeviceGetOutputChannelValue(dsid string, channels []string) (*D
return wrapApiResponse[DeviceGetOutputChannelValueResponse](response, err)
}

func (c *client) DeviceGetMaxMotionTime(dsid string) (*DeviceGetMaxMotionTimeResponse, error) {
params := url.Values{}
params.Set("dsid", dsid)
response, err := c.apiCall("json/device/getMaxMotionTime", params)
return wrapApiResponse[DeviceGetMaxMotionTimeResponse](response, err)
}

func (c *client) EventSubscribe(event EventType, eventCallback EventCallback) error {
c.eventMutex.Lock()
defer c.eventMutex.Unlock()
Expand Down

0 comments on commit f509edb

Please sign in to comment.