tools

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tools contains various tools to make it easier to use the Tado API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errors added in v2.0.1

func Errors(errs *tado.ErrorResponse) error

Errors converts the errors in ErrorResponse to a Go error

func Errors422 added in v2.0.1

func Errors422(errs *tado.ErrorResponse422) error

Errors422 converts the errors in ErrorResponse422 to a Go error

func GetHomes

func GetHomes(ctx context.Context, client TadoClient) ([]tado.HomeBase, error)

GetHomes returns the list of Home ID's that are registered under the user's account.

func HandleErrors added in v2.3.1

func HandleErrors(resp *http.Response, tadoErrors map[int]any) error

HandleErrors converts an HTTP error received from the server to a generic Go error. resp should be the http.Response received, and tadoErrors a map of received Error objects by HTTP StatusCode, for example:

me, err := client.GetMeWithResponse(ctx)
if err != nil {
	return nil, fmt.Errorf("GetMeWithResponse: %w", err)
}
if me.StatusCode() != http.StatusOK {
	return nil, HandleErrors(me.HTTPResponse, map[int]any{
		http.StatusUnauthorized: me.JSON401,
	})
}

Types

type TadoClient added in v2.0.1

type TadoClient interface {
	GetMeWithResponse(ctx context.Context, reqEditors ...tado.RequestEditorFn) (*tado.GetMeResponse, error)
}

Jump to

Keyboard shortcuts

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