From d1cd52cfc71ad6fe0cd2252b3f41987820b2c5ed Mon Sep 17 00:00:00 2001 From: Maximilian Kalus Date: Fri, 26 Feb 2021 00:40:05 +0100 Subject: [PATCH] Add more device capabilities, especially humidity sensor introduced in FritzOS 7.25. --- fritz/device.go | 35 ++++++++++++++++++++++++++++++++++- fritz/device_test.go | 2 ++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/fritz/device.go b/fritz/device.go index 1b211cc6..4a68251a 100644 --- a/fritz/device.go +++ b/fritz/device.go @@ -4,13 +4,14 @@ 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 _ _ _ AlertTrigger - _ + AVMButton HeatControl PowerSensor TemperatureSensor @@ -19,6 +20,13 @@ const ( Microphone _ HANFUNUnit + _ + SwitchableDevice + DimmableDevice + ColorSettableDevice + _ + _ + HumiditySensor ) // Device models a smart home device. This corresponds to @@ -54,6 +62,11 @@ func (d *Device) HasAlertSensor() bool { return d.Has(AlertTrigger) } +// IsAVMButton returns true if the device is an AVM button like the FRITZ!DECT 440 and returns false otherwise. +func (d *Device) IsAVMButton() bool { + return d.Has(AVMButton) +} + // IsThermostat returns true if the device is recognized to be a HKR device and returns false otherwise. func (d *Device) IsThermostat() bool { return d.Has(HeatControl) @@ -89,6 +102,26 @@ 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) +} + // Has checks the passed capabilities and returns true iff the device supports all capabilities. func (d *Device) Has(cs ...Capability) bool { for _, c := range cs { diff --git a/fritz/device_test.go b/fritz/device_test.go index 8a16894e..e4318472 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: "1048864 is an AVM button", mask: "1048864", fct: (*Device).IsAVMButton, expect: true}, + {name: "1048864 can measure humidity", mask: "1048864", fct: (*Device).CanMeasureHumidity, expect: true}, } { t.Run(tc.name, func(t *testing.T) { device := &Device{Functionbitmask: tc.mask}