Skip to content

Commit

Permalink
position signal to shutter
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsgrill committed Jul 4, 2024
1 parent 9edf4ee commit 75f36d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
11 changes: 6 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ type BasicConfig struct {

type Cover struct {
BasicConfig
CommandTopic string `json:"command_topic,omitempty"`
Name string `json:"name,omitempty"`
PositionTopic string `json:"position_topic,omitempty"`
PositionOpen int `json:"position_open"`
PositionClosed int `json:"position_closed"`
CommandTopic string `json:"command_topic,omitempty"`
Name string `json:"name,omitempty"`
PositionTopic string `json:"position_topic,omitempty"`
PositionTemplate string `json:"position_template,omitempty"`
PositionOpen int `json:"position_open"`
PositionClosed int `json:"position_closed"`
}

type DInput struct {
Expand Down
2 changes: 2 additions & 0 deletions devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type IBasicShutter interface {
Open()
Close()
Stop()
Range() int
Position() ISensor[int]
}

type IShutter interface {
Expand Down
30 changes: 28 additions & 2 deletions proxy/shutter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
package proxy

import "github.com/home2mqtt/hass"
import (
"strconv"

"github.com/home2mqtt/hass"
)

type shutter struct {
baseActuator
basic bool
basic bool
positionrange int
position hass.ISensor[int]
}

// Position implements hass.IShutter.
func (s *shutter) Position() hass.ISensor[int] {
return s.position
}

// Range implements hass.IShutter.
func (s *shutter) Range() int {
return s.positionrange
}

func BasicShutter(runtime hass.IPubSubRuntime, conf *hass.Cover) hass.IShutter {
Expand All @@ -17,6 +33,16 @@ func BasicShutter(runtime hass.IPubSubRuntime, conf *hass.Cover) hass.IShutter {

func Shutter(runtime hass.IPubSubRuntime, conf *hass.Cover) hass.IShutter {
result := &shutter{}
if conf.PositionOpen != 0 {
result.positionrange = conf.PositionOpen - conf.PositionClosed
} else {
result.positionrange = 100
}
if conf.PositionTopic != "" {
result.position = hass.ChanToSensor(ParseSensorValue(runtime, conf.PositionTopic, conf.PositionTemplate, func(s string) (int, error) {
return strconv.Atoi(s)
}))
}
result.init(runtime, conf.CommandTopic)
return result
}
Expand Down

0 comments on commit 75f36d9

Please sign in to comment.