diff --git a/fritz/device.go b/fritz/device.go index 4a68251a..7b6a4243 100644 --- a/fritz/device.go +++ b/fritz/device.go @@ -4,7 +4,6 @@ package fritz type Capability int // Known (specified) device capabilities. -// see https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AHA-HTTP-Interface.pdf section 3.2 for full list const ( HANFUNCompatibility Capability = iota _ @@ -21,9 +20,9 @@ const ( _ HANFUNUnit _ - SwitchableDevice - DimmableDevice - ColorSettableDevice + _ + _ + _ _ _ HumiditySensor @@ -102,21 +101,6 @@ func (d *Device) HasHANFUNUnit() bool { return d.Has(HANFUNUnit) } -// IsSwitchableDevice returns true if the device is a switchable device/power plug/actor. -func (d *Device) IsSwitchableDevice() bool { - return d.Has(SwitchableDevice) -} - -// CanBeDimmed returns true if the device can be dimmed somehow (e.g. light intensity, height level, etc.). -func (d *Device) CanBeDimmed() bool { - return d.Has(DimmableDevice) -} - -// CanSetColors returns true if the device can set colors. -func (d *Device) CanSetColors() bool { - return d.Has(ColorSettableDevice) -} - // CanMeasureHumidity returns true if the device has humidity functionality. Returns false otherwise. func (d *Device) CanMeasureHumidity() bool { return d.Has(HumiditySensor) diff --git a/fritz/device_test.go b/fritz/device_test.go index e4318472..59c03c7d 100644 --- a/fritz/device_test.go +++ b/fritz/device_test.go @@ -31,6 +31,8 @@ func TestParsingFunctionBitMask(t *testing.T) { {name: "320 has no microphone", mask: "320", fct: (*Device).HasMicrophone, expect: false}, {name: "320 has no hanfun unit", mask: "320", fct: (*Device).HasHANFUNUnit, expect: false}, {name: "320 does not speak hanfun protocol", mask: "320", fct: (*Device).IsHANFUNCompatible, expect: false}, + {name: "320 can not measure humidity", mask: "320", fct: (*Device).CanMeasureHumidity, expect: false}, + {name: "320 is not AVM button", mask: "320", fct: (*Device).IsAVMButton, expect: false}, {name: "1048864 is an AVM button", mask: "1048864", fct: (*Device).IsAVMButton, expect: true}, {name: "1048864 can measure humidity", mask: "1048864", fct: (*Device).CanMeasureHumidity, expect: true}, } { diff --git a/fritz/devicelist.go b/fritz/devicelist.go index 05a276c9..656023be 100644 --- a/fritz/devicelist.go +++ b/fritz/devicelist.go @@ -43,6 +43,13 @@ func (l *Devicelist) Buttons() []Device { }) } +// AVMButtons returns the devices which satisfy IsAVMButton. +func (l *Devicelist) AVMButtons() []Device { + return l.filter(func(d Device) bool { + return d.IsAVMButton() + }) +} + func (l *Devicelist) filter(predicate func(Device) bool) []Device { var filtered []Device for _, d := range l.Devices { diff --git a/fritz/devicelist_test.go b/fritz/devicelist_test.go index cdbe33d3..8e5cca1f 100644 --- a/fritz/devicelist_test.go +++ b/fritz/devicelist_test.go @@ -22,6 +22,7 @@ func TestDeviceFiltering(t *testing.T) { {name: "on buttons", xmlfile: "../testdata/devicelist_fritzos06.83.xml", filter: func(d Devicelist) []Device { return d.Buttons() }, expect: 0}, {name: "four thermostats (Issue #56)", xmlfile: "../testdata/devicelist_issue_59.xml", filter: func(d Devicelist) []Device { return d.Thermostats() }, expect: 4}, {name: "eight switches (Issue #56)", xmlfile: "../testdata/devicelist_issue_59.xml", filter: func(d Devicelist) []Device { return d.Switches() }, expect: 8}, + {name: "two avm buttons", xmlfile: "../testdata/devicelist_fritzos07.29.xml", filter: func(d Devicelist) []Device { return d.AVMButtons() }, expect: 2}, } { t.Run(tc.name, func(t *testing.T) { list := mustUnmarshall(t, tc.xmlfile) diff --git a/testdata/devicelist_fritzos07.29.xml b/testdata/devicelist_fritzos07.29.xml new file mode 100644 index 00000000..574b5011 --- /dev/null +++ b/testdata/devicelist_fritzos07.29.xml @@ -0,0 +1,236 @@ + + + 1 + 0 + SWITCH_1 + + 0 + auto + 0 + 0 + + + 0 + + + 231090 + 0 + 369382 + + + 165 + 0 + + + + 1 + 0 + HKR_1 + 60 + 0 + + 195 + 0 + + + 39 + 32 + 32 + 38 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 60 + + 1644177600 + 38 + + 0 + 0 + + + + 1 + 0 + HKR_2 + 70 + 0 + + 145 + -5 + + + 29 + 253 + 32 + 40 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 70 + + 1644177600 + 40 + + 0 + 0 + + + + 1 + 0 + HKR_3 + 10 + 0 + + 130 + -20 + + + 26 + 253 + 32 + 37 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 10 + + 1644213600 + 37 + + 0 + 0 + + + + 1 + 0 + HKR_4 + 1 + 0 + + 180 + -10 + + + 36 + 34 + 32 + 34 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + + 1644174000 + 32 + + 0 + 0 + + + + 1 + 0 + SWITCH_2 + + 1 + manuell + 0 + 1 + + + 1 + + + 230602 + 0 + 46752 + + + 125 + 0 + + + + 1 + 0 + BUTTON_1 + 100 + 0 + + 175 + 0 + + + 54 + + + + + + + + 1 + 0 + BUTTON_2 + 100 + 0 + + 200 + 0 + + + 38 + + + + + + + \ No newline at end of file