fritzbox

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2020 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability

type Capability int

Capability enumerates the device capabilities.

const (
	HANFUNCompatibility Capability = iota

	AlertTrigger

	HeatControl
	PowerSensor
	TemperatureSensor
	StateSwitch
	DECTRepeater
	Microphone

	HANFUNUnit
)

Known (specified) device capabilities.

noinspection GoUnusedConst

type Client

type Client struct {
	Username string
	Password string
	BaseURL  url.URL // must not be a pointer to avoid modifying this URL during our requests
	// contains filtered or unexported fields
}

func New

func New(baseURL, username, password string, logger *zap.Logger) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Devices

func (c *Client) Devices(ctx context.Context) ([]Device, error)

func (*Client) NetworkStats

func (c *Client) NetworkStats(ctx context.Context) (*TrafficMonitoringData, error)

type Device

type Device struct {
	Identifier         string `xml:"identifier,attr"`      // A unique ID like AIN, MAC address, etc.
	InternalID         string `xml:"id,attr"`              // Internal device ID of the FRITZ!Box.
	CapabilitiesBitmap string `xml:"functionbitmask,attr"` // Bitmask determining the functionality of the device: bit 6: Comet DECT, HKR, "thermostat", bit 7: energy measurement device, bit 8: temperature sensor, bit 9: switch, bit 10: AVM DECT repeater
	FirmwareVersion    string `xml:"fwversion,attr"`       // Firmware version of the device.
	Manufacturer       string `xml:"manufacturer,attr"`    // Manufacturer of the device, usually set to "AVM".
	ProductName        string `xml:"productname,attr"`     // Name of the product, empty for unknown or undefined devices.
	Present            int    `xml:"present"`              // Device connected (1) or not (0).
	Name               string `xml:"name"`                 // The name of the device. Can be assigned in the web gui of the FRITZ!Box.

	Switch      SwitchInfo      `xml:"switch"`
	Power       PowerInfo       `xml:"powermeter"`
	Temperature TemperatureInfo `xml:"temperature"`

	Thermostat struct {
		Measured   string `xml:"tist"`    // Measured temperature.
		Goal       string `xml:"tsoll"`   // Desired temperature, user controlled.
		Saving     string `xml:"absenk"`  // Energy saving temperature.
		Comfort    string `xml:"komfort"` // Comfortable temperature.
		NextChange struct {
			TimeStamp string `xml:"endperiod"` // Timestamp (epoch time) when the next temperature switch is scheduled.
			Goal      string `xml:"tchange"`   // The temperature to switch to. Same unit convention as in Thermostat.Measured.
		} `xml:"nextchange"` // The next scheduled temperature change.
		Lock       string `xml:"lock"`             // Switch locked (box defined)? 1/0 (empty if not known or if there was an error).
		DeviceLock string `xml:"devicelock"`       // Switch locked (device defined)? 1/0 (empty if not known or if there was an error).
		ErrorCode  string `xml:"errorcode"`        // Error codes: 0 = OK, 1 = ... see https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AHA-HTTP-Interface.pdf.
		BatteryLow string `xml:"batterylow"`       // "0" if the battery is OK, "1" if it is running low on capacity.
		WindowOpen string `xml_:"windowopenactiv"` // "1" if detected an open window (usually turns off heating), "0" if not.
	} `xml:"hkr"`

	AlertSensor struct {
		State string `xml:"state"` // Last transmitted alert state, "0" - no alert, "1" - alert, "" if unknown or upon errors.
	} `xml:"alert"`

	Button struct {
		LastPressedTimestamp string `xml:"lastpressedtimestamp"` // Timestamp (in epoch seconds) when the button was last pressed. "0" or "" if unknown.
	} `xml:"button"`
}

func (*Device) CanMeasurePower

func (d *Device) CanMeasurePower() bool

func (*Device) CanMeasureTemperature

func (d *Device) CanMeasureTemperature() bool

func (*Device) Has

func (d *Device) Has(cs ...Capability) bool

Has checks the passed capabilities and returns true iff the device supports all capabilities.

func (*Device) IsSwitch

func (d *Device) IsSwitch() bool

type DeviceList

type DeviceList struct {
	Devices []Device `xml:"device"`
}

type Permissions

type Permissions struct {
	Names        []string `xml:"Name"`
	AccessLevels []string `xml:"Access"`
}

type PowerInfo

type PowerInfo struct {
	Power   string `xml:"power"`   // Electric power in milli Watt, refreshed approx every 2 minutes
	Energy  string `xml:"energy"`  // Accumulated power consumption since initial setup
	Voltage string `xml:"voltage"` // Electric voltage in milli Volt, refreshed approx every 2 minutes
}

func (PowerInfo) GetEnergy

func (i PowerInfo) GetEnergy() float64

func (PowerInfo) GetPower

func (i PowerInfo) GetPower() float64

func (PowerInfo) GetVoltage

func (i PowerInfo) GetVoltage() float64

type Session

type Session struct {
	Challenge string      `xml:"Challenge"` // A challenge provided by the FRITZ!Box.
	SID       string      `xml:"SID"`       // The session id issued by the FRITZ!Box, "0000000000000000" is considered invalid/"no session".
	BlockTime string      `xml:"BlockTime"` // The time that needs to expire before the next login attempt can be made.
	Rights    Permissions `xml:"Rights"`    // The Rights associated withe the session.
}

See https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf.

type SwitchInfo

type SwitchInfo struct {
	State      string `xml:"state"`      // Switch state 1/0 on/off (empty if not known or if there was an error).
	Mode       string `xml:"mode"`       // Switch mode manual/automatic (empty if not known or if there was an error).
	Lock       string `xml:"lock"`       // Switch locked (box defined)? 1/0 (empty if not known or if there was an error).
	DeviceLock string `xml:"devicelock"` // Switch locked (device defined)? 1/0 (empty if not known or if there was an error).
}

func (SwitchInfo) IsPoweredOn

func (i SwitchInfo) IsPoweredOn() bool

type TemperatureInfo

type TemperatureInfo struct {
	Celsius string `xml:"celsius"` // Temperature measured at the device sensor in units of 0.1 °C. Negative and positive values are possible.
	Offset  string `xml:"offset"`  // Temperature offset (set by the user) in units of 0.1 °C. Negative and positive values are possible.
}

func (TemperatureInfo) GetCelsius

func (i TemperatureInfo) GetCelsius() float64

type TrafficMonitoringData

type TrafficMonitoringData struct {
	DownstreamInternet      []float64 `json:"ds_bps_curr"`
	DownStreamMedia         []float64 `json:"ds_mc_bps_curr"`
	DownStreamGuest         []float64 `json:"ds_guest_bps_curr"`
	UpstreamRealtime        []float64 `json:"us_realtime_bps_curr"`
	UpstreamHighPriority    []float64 `json:"us_important_bps_curr"`
	UpstreamDefaultPriority []float64 `json:"us_default_bps_curr"`
	UpstreamLowPriority     []float64 `json:"us_background_bps_curr"`
	UpstreamGuest           []float64 `json:"guest_us_bps"`
}

20 values representing the last 100 seconds in 20 buckets of 5 seconds each. Apparently the values are *Bytes* per second (not bits)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL