Skip to content

Commit

Permalink
Add more device capabilities, especially humidity sensor introduced i…
Browse files Browse the repository at this point in the history
…n FritzOS 7.25.
  • Loading branch information
mkalus authored and jayme-github committed Feb 6, 2022
1 parent 6884508 commit d1cd52c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 34 additions & 1 deletion fritz/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +20,13 @@ const (
Microphone
_
HANFUNUnit
_
SwitchableDevice
DimmableDevice
ColorSettableDevice
_
_
HumiditySensor
)

// Device models a smart home device. This corresponds to
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions fritz/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit d1cd52c

Please sign in to comment.