Sunspec: honor scale factors when writing (#16209)

This commit is contained in:
andig 2024-09-18 22:50:03 +02:00 • committed by GitHub
parent c288c9ba62
commit 57e1de7a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

2
go.mod
View file

@ -8,7 +8,7 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/PuerkitoBio/goquery v1.9.2
github.com/andig/go-powerwall v0.2.1-0.20230808194509-dd70cdb6e140
github.com/andig/gosunspec v0.0.0-20231205122018-1daccfa17912
github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/aws/aws-sdk-go v1.55.5

4
go.sum
View file

@ -29,8 +29,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/andig/go-powerwall v0.2.1-0.20230808194509-dd70cdb6e140 h1:C93T8vg7CN4Q4BBDbBMOvBoTYBA+CaBEvlY2SZF8aa0=
github.com/andig/go-powerwall v0.2.1-0.20230808194509-dd70cdb6e140/go.mod h1:Xk09mD+7RTCuuHMX5RxlqgEUeh9oZdIX0rL0qiY6l/4=
github.com/andig/gosunspec v0.0.0-20231205122018-1daccfa17912 h1:pphS+WUa9zK0ZH/Rt2JMEaOx0qz8dDzOzbr/W7BMiXQ=
github.com/andig/gosunspec v0.0.0-20231205122018-1daccfa17912/go.mod h1:c6P6szcR+ROkqZruOR4f6qbDKFjZX6OitPpj+yJ/r8k=
github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b h1:81UMfM949I7StrRay7YDUZazY8M1u/JHkzwcFEjiilQ=
github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b/go.mod h1:c6P6szcR+ROkqZruOR4f6qbDKFjZX6OitPpj+yJ/r8k=
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e h1:m/NTP3JWpR7M0ljLxiQU4fzR25jjhe1LDtxLMNcoNJQ=
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e/go.mod h1:4VtYzTm//oUipwvO3yh0g/udTE7pYJM+U/kyAuFDsgM=
github.com/andig/yaml v0.0.0-20240531135838-1ff5761ab467 h1:JqIoHxsQSV39xaemvVRu3HOkSf5AbhQ1YEENJa2cL3Q=

View file

@ -161,8 +161,6 @@ func (m *ModbusSunspec) blockPoint() (block sunspec.Block, point sunspec.Point,
return block, point, err
}
// TODO scale factors
var _ SetFloatProvider = (*Modbus)(nil)
// FloatSetter executes configured modbus write operation and implements SetFloatProvider
@ -213,6 +211,7 @@ func (m *ModbusSunspec) IntSetter(_ string) (func(int64) error, error) {
val = int64(float64(val) * m.scale)
// SetValue is used to include the scale factor when writing
switch typ {
case typelabel.Bitfield16:
point.SetBitfield16(sunspec.Bitfield16(val))
@ -223,17 +222,17 @@ func (m *ModbusSunspec) IntSetter(_ string) (func(int64) error, error) {
case typelabel.Enum32:
point.SetEnum32(sunspec.Enum32(val))
case typelabel.Int16:
point.SetInt16(int16(val))
point.SetValue(int16(val))
case typelabel.Int32:
point.SetInt32(int32(val))
point.SetValue(int32(val))
case typelabel.Int64:
point.SetInt64(val)
point.SetValue(val)
case typelabel.Uint16:
point.SetUint16(uint16(val))
point.SetValue(uint16(val))
case typelabel.Uint32:
point.SetUint32(uint32(val))
point.SetValue(uint32(val))
case typelabel.Uint64:
point.SetUint64(uint64(val))
point.SetValue(uint64(val))
default:
return fmt.Errorf("invalid point type: %s", typ)
}