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

Custom charger: add typical meter measurements #14546

Merged
merged 4 commits into from
Jul 6, 2024
Merged

Conversation

andig
Copy link
Member

@andig andig commented Jun 24, 2024

Fix #14508

@andig andig added the enhancement New feature or request label Jun 24, 2024
@andig
Copy link
Member Author

andig commented Jun 24, 2024

Wow, der PR hat 27000 Zeilen generierten Code geändert. Langsam mache ich mir Sorgen!

UPDATE binary geht von 103MB auf 117MB auf dem Mac. Das ist leider ein No-Go!

@GrimmiMeloni dazu fällt dir auch nichts ein, oder?

@andig andig force-pushed the feat/charger-measurements branch from 28200a1 to 806d851 Compare June 24, 2024 18:54
@andig andig marked this pull request as draft June 24, 2024 18:54
@andig
Copy link
Member Author

andig commented Jun 24, 2024

Zwei (hässliche) Optimierungsideen fallen mir ein:

  • falls es meter nicht gibt ist die ganze Kombinatorik der weiteren Strommesswerte irrelavant, sie könnten also entfallen.
  • ich frage mich, ob es irgendwie möglich wäre, einen Sum-Type (struct) aus spezifischem Charger und spezifischem Meter zu erzeugen, aber jedes nur für sich zu erzeugen

@andig
Copy link
Member Author

andig commented Jun 26, 2024

@GrimmiMeloni I've prototyped the idea above. This does work:

func TestMeterDecoration(t *testing.T) {
	ctrl := gomock.NewController(t)

	type chargerStruct = struct {
		api.Charger
		api.PhaseSwitcher
	}

	charger := chargerStruct{
		api.NewMockCharger(ctrl),
		api.NewMockPhaseSwitcher(ctrl),
	}

	assert.Implements(t, (*api.Charger)(nil), charger)
	assert.Implements(t, (*api.PhaseSwitcher)(nil), charger)

	meter := api.NewMockMeter(ctrl)

	combined := struct {
		chargerStruct
		api.Meter
	}{
		charger,
		meter,
	}

	assert.Implements(t, (*api.Charger)(nil), combined)
	assert.Implements(t, (*api.PhaseSwitcher)(nil), combined)
	assert.Implements(t, (*api.Meter)(nil), combined)
}

while this doesn't:

func TestMeterDecoration(t *testing.T) {
	ctrl := gomock.NewController(t)

	charger := struct {
		api.Charger
		api.PhaseSwitcher
	}{
		api.NewMockCharger(ctrl),
		api.NewMockPhaseSwitcher(ctrl),
	}

	assert.Implements(t, (*api.Charger)(nil), charger)
	assert.Implements(t, (*api.PhaseSwitcher)(nil), charger)

	meter := api.NewMockMeter(ctrl)

	combined := struct {
		api.Charger
		api.Meter
	}{
		charger,
		meter,
	}

	assert.Implements(t, (*api.Charger)(nil), combined)
	assert.Implements(t, (*api.PhaseSwitcher)(nil), combined)
	assert.Implements(t, (*api.Meter)(nil), combined)
}

This makes me think that it might work to partition the combinations and build a combined type of specific charger and meter sub types.

@andig
Copy link
Member Author

andig commented Jun 26, 2024

@github-actions github-actions bot added the stale Outdated and ready to close label Jul 3, 2024
@andig andig added infrastructure Basic functionality backlog Things to do later and removed enhancement New feature or request stale Outdated and ready to close labels Jul 3, 2024
@andig andig marked this pull request as ready for review July 6, 2024 14:12
@andig andig merged commit a367a1e into master Jul 6, 2024
5 of 6 checks passed
@andig andig deleted the feat/charger-measurements branch July 6, 2024 14:13
@andig
Copy link
Member Author

andig commented Jul 14, 2024

Testcase nochmal aktualisiert:

package main

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

type If1 interface {
	F1()
}

type If1Impl struct{}

func (i *If1Impl) F1() {
}

type If2 interface {
	F2()
}

type If2Impl struct{}

func (i *If2Impl) F2() {
}

type If3 interface {
	F3()
}

type If3Impl struct{}

func (i *If3Impl) F3() {
}

type If12 interface {
	If1
	If2
}

func TestEmbedding(t *testing.T) {
	type if12T struct {
		If1
		If2
	}

	if12 := if12T{
		new(If1Impl),
		new(If2Impl),
	}

	meter := new(If3Impl)

	check := func(i any, msg string) {
		assert.Implements(t, (*If1)(nil), i, msg)
		assert.Implements(t, (*If2)(nil), i, msg)
		assert.Implements(t, (*If3)(nil), i, msg)
	}

	structs := struct {
		*if12T
		If3
	}{
		&if12,
		meter,
	}
	check(structs, "structs")

	interfaces := struct {
		If12
		If3
	}{
		if12,
		meter,
	}
	check(interfaces, "interfaces")

	interfaces2 := struct {
		If1
		If3
	}{
		if12,
		meter,
	}
	check(interfaces2, "implicit interfaces")
}

ergibt:

--- FAIL: TestEmbedding (0.00s)
    /Users/andig/htdocs/interfaces/main_test.go:56: 
        	Error Trace:	/Users/andig/htdocs/interfaces/main_test.go:56
        	            				/Users/andig/htdocs/interfaces/main_test.go:85
        	Error:      	struct { main.If1; main.If3 } must implement main.If2
        	Test:       	TestEmbedding
        	Messages:   	implicit interfaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Things to do later infrastructure Basic functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom charger: add more apis
1 participant