Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with heatpumps #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions cmd/hems/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"syscall"
"time"

"github.com/enbility/eebus-go/features"
"github.com/enbility/eebus-go/logging"
"github.com/enbility/eebus-go/service"
"github.com/enbility/eebus-go/spine"
"github.com/enbility/eebus-go/spine/model"
)

Expand Down Expand Up @@ -80,6 +83,8 @@ func (h *hems) run() {
os.Exit(0)
}

spine.Events.Subscribe(h)

h.myService.Start()
// defer h.myService.Shutdown()

Expand All @@ -102,6 +107,93 @@ func (h *hems) HandleEVSEDeviceState(ski string, failure bool, errorCode string)
fmt.Println("EVSE Error State:", failure, errorCode)
}

func (h *hems) HandleEvent(payload spine.EventPayload) {
switch payload.EventType {
case spine.EventTypeEntityChange:
entityType := payload.Entity.EntityType()

switch payload.ChangeType {
case spine.ElementChangeAdd:
switch entityType {
case model.EntityTypeTypeDeviceInformation:
h.deviceInformationConnected(payload.Entity)
case model.EntityTypeTypeGeneric:
h.heatpumpConnected(payload.Entity)
}
}
}
}

func (h *hems) deviceInformationConnected(entity *spine.EntityRemoteImpl) {
localDevice := h.myService.LocalDevice()

deviceClassification, _ := features.NewDeviceClassification(model.RoleTypeClient, model.RoleTypeServer, localDevice, entity)

if deviceClassification != nil {
if _, err := deviceClassification.RequestManufacturerDetails(); err != nil {
logging.Log.Debug(err)
}
}
}

func (h *hems) heatpumpConnected(entity *spine.EntityRemoteImpl) {
localDevice := h.myService.LocalDevice()

electricalConnection, _ := features.NewElectricalConnection(model.RoleTypeClient, model.RoleTypeClient, localDevice, entity)
measurement, _ := features.NewMeasurement(model.RoleTypeClient, model.RoleTypeClient, localDevice, entity)
hvac, _ := features.NewHVAC(model.RoleTypeClient, model.RoleTypeClient, localDevice, entity)

if electricalConnection != nil {
if err := electricalConnection.SubscribeForEntity(); err != nil {
logging.Log.Error(err)
}

if err := electricalConnection.RequestDescriptions(); err != nil {
logging.Log.Error(err)
}

if err := electricalConnection.RequestParameterDescriptions(); err != nil {
logging.Log.Error(err)
}
}

if measurement != nil {
if err := measurement.SubscribeForEntity(); err != nil {
logging.Log.Error(err)
}

if err := measurement.RequestDescriptions(); err != nil {
logging.Log.Error(err)
}

if err := measurement.RequestConstraints(); err != nil {
logging.Log.Error(err)
}

if _, err := measurement.RequestValues(); err != nil {
logging.Log.Error(err)
}
}

if hvac != nil {
if err := hvac.SubscribeForEntity(); err != nil {
logging.Log.Error(err)
}

if _, err := hvac.RequestOverrunDescriptions(); err != nil {
logging.Log.Error(err)
}

if _, err := hvac.RequestOverrunValues(); err != nil {
logging.Log.Error(err)
}

if _, err := hvac.RequestSystemFunctionDescriptions(); err != nil {
logging.Log.Error(err)
}
}
}

// main app
func usage() {
fmt.Println("First Run:")
Expand Down
8 changes: 7 additions & 1 deletion features/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ func (f *FeatureImpl) getLocalClientAndRemoteServerFeatures() (spine.FeatureLoca
}

if featureRemote == nil {
return nil, nil, errors.New("remote feature not found")
// as a backup, check if there is a Generic feature type available instead
// some heatpumps use a Generic feature type for everything
featureRemote = f.entity.Device().FeatureByEntityTypeAndRole(f.entity, model.FeatureTypeTypeGeneric, f.remoteRole)

if featureRemote == nil {
return nil, nil, errors.New("remote feature not found")
}
}

return featureLocal, featureRemote, nil
Expand Down
183 changes: 183 additions & 0 deletions features/hvac.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package features

import (
"github.com/enbility/eebus-go/spine"
"github.com/enbility/eebus-go/spine/model"
)

type HVAC struct {
*FeatureImpl
}

func NewHVAC(localRole, remoteRole model.RoleType, spineLocalDevice *spine.DeviceLocalImpl, entity *spine.EntityRemoteImpl) (*HVAC, error) {
feature, err := NewFeatureImpl(model.FeatureTypeTypeHvac, localRole, remoteRole, spineLocalDevice, entity)
if err != nil {
return nil, err
}

i := &HVAC{
FeatureImpl: feature,
}

return i, nil
}

// request FunctionTypeHvacOverrunDescriptionListData from a remote entity
func (i *HVAC) RequestOverrunDescriptions() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacOverrunDescriptionListData, nil, nil)
}

// return current values for Hvac Overrun Descriptions
func (i *HVAC) GetOverrunDescriptions() ([]model.HvacOverrunDescriptionDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacOverrunDescriptionListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacOverrunDescriptionListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacOverrunDescriptionData, nil
}

// request FunctionTypeHvacOverrunListData from a remote entity
func (i *HVAC) RequestOverrunValues() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacOverrunListData, nil, nil)
}

// return current values for HvacOverrun
func (i *HVAC) GetValues() ([]model.HvacOverrunDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacOverrunListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacOverrunListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacOverrunData, nil
}

// request FunctionTypeHvacSystemFunctionDescriptionListData from a remote entity
func (i *HVAC) RequestSystemFunctionDescriptions() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacSystemFunctionDescriptionListData, nil, nil)
}

// return current values for Hvac System Function Descriptions
func (i *HVAC) GetSystemFunctionDescriptions() ([]model.HvacSystemFunctionDescriptionDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacSystemFunctionDescriptionListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacSystemFunctionDescriptionListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacSystemFunctionDescriptionData, nil
}

// request FunctionTypeHvacSystemFunctionListData from a remote entity
func (i *HVAC) RequestSystemFunctionValues() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacSystemFunctionListData, nil, nil)
}

// return current values for Hvac System Function Values
func (i *HVAC) GetSystemFunctionValues() ([]model.HvacSystemFunctionDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacSystemFunctionListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacSystemFunctionListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacSystemFunctionData, nil
}

// request FunctionTypeHvacSystemFunctionOperationModeRelationListData from a remote entity
func (i *HVAC) RequestSystemFunctionOperationModeRelationValues() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacSystemFunctionOperationModeRelationListData, nil, nil)
}

// return current values for Hvac System Function Operation Mode Relation Values
func (i *HVAC) GetSystemFunctionOperationModeRelationValues() ([]model.HvacSystemFunctionOperationModeRelationDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacSystemFunctionOperationModeRelationListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacSystemFunctionOperationModeRelationListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacSystemFunctionOperationModeRelationData, nil
}

// request FunctionTypeHvacSystemFunctionPowerSequenceRelationListData from a remote entity
func (i *HVAC) RequestSystemFunctionPowerSequenceRelationValues() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacSystemFunctionPowerSequenceRelationListData, nil, nil)
}

// return current values for Hvac System Function Power Sequence Relation Values
func (i *HVAC) GetSystemFunctionPowerSequenceRelationValues() ([]model.HvacSystemFunctionPowerSequenceRelationDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacSystemFunctionPowerSequenceRelationListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacSystemFunctionPowerSequenceRelationListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacSystemFunctionPowerSequenceRelationData, nil
}

// request FunctionTypeHvacSystemFunctionSetPointRelationListData from a remote entity
func (i *HVAC) RequestSystemFunctionSetpointRelationValues() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacSystemFunctionSetPointRelationListData, nil, nil)
}

// return current values for Hvac System Function Power Sequence Relation Values
func (i *HVAC) GetSystemFunctionSetpointRelationValues() ([]model.HvacSystemFunctionSetpointRelationDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacSystemFunctionSetPointRelationListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacSystemFunctionSetpointRelationListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacSystemFunctionSetpointRelationData, nil
}

// request FunctionTypeHvacOperationModeDescriptionListData from a remote entity
func (i *HVAC) RequestOperationModeDescriptions() (*model.MsgCounterType, error) {
return i.requestData(model.FunctionTypeHvacOperationModeDescriptionListData, nil, nil)
}

// return current values for Hvac System Function Power Sequence Relation Values
func (i *HVAC) GetOperationModeDescriptions() ([]model.HvacOperationModeDescriptionDataType, error) {
rData := i.featureRemote.Data(model.FunctionTypeHvacOperationModeDescriptionListData)
if rData == nil {
return nil, ErrDataNotAvailable
}

data := rData.(*model.HvacOperationModeDescriptionListDataType)
if data == nil {
return nil, ErrDataNotAvailable
}

return data.HvacOperationModeDescriptionData, nil
}