natureremo

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 12 Imported by: 15

README

Nature Remo API Client for Go Go ReferenceGo Report Card

tenntenn/natureremo is Nature Remo API Client for Go. Nature Remo is a smart remote control that easily realizes smart home by connecting your appliances to the Internet.

Install

$ go get -u github.com/tenntenn/natureremo

Examples

See _example directory.

func main() {
	cli := natureremo.NewClient(os.Args[1])
	ctx := context.Background()

	applianceName := os.Args[2]
	signalName := os.Args[3]

	as, err := cli.ApplianceService.GetAll(ctx)
	if err != nil {
		log.Fatal(err)
	}

	var target *natureremo.Appliance
	for _, a := range as {
		if a.Nickname == applianceName {
			target = a
			break
		}
	}

	if target == nil {
		log.Fatalf("%s not found", applianceName)
	}

	for _, s := range target.Signals {
		if s.Name == signalName {
			cli.SignalService.Send(ctx, s)
			break
		}
	}
}

Supported API

Cloud API

http://swagger.nature.global

Status Endpoint HTTP Method Service
/1/users/me GET UserService
/1/users/me POST UserService
/1/devices GET DeviceService
/1/devices/{device} POST DeviceService
/1/devices/{device}/delete POST DeviceService
/1/devices/{device}/temperature_offset POST DeviceService
/1/devices/{device}/humidity_offset POST DeviceService
/1/detectappliance POST ApplianceService
/1/appliances GET ApplianceService
/1/appliances POST ApplianceService
/1/appliance_orders POST ApplianceService
/1/appliances/{appliance}/delete POST ApplianceService
/1/appliances/{appliance} POST ApplianceService
/1/appliances/{appliance}/aircon_settings POST ApplianceService
/1/appliances/{appliance}/tv POST ApplianceService
/1/appliances/{appliance}/light POST ApplianceService
/1/appliances/{appliance}/signals GET SignalService
/1/appliances/{appliance}/signals POST SignalService
/1/appliances/{appliance}/signal_orders POST SignalService
/1/signals/{signal} POST SignalService
/1/signals/{signal}/delete POST SignalService
/1/signals/{signal}/send POST SignalService
Local API

http://local.swagger.nature.global/

Status Endpoint HTTP Method LocalClient Method
/messages GET Fetch
/messages POST Emit

Documentation

Overview

Package natureremo provides API Client of Nature Remo.

You can see overview of Nature Remo API on below URL. https://developer.nature.global/en/overview/

Index

Constants

View Source
const (
	// AirVolumeAuto represents auto.
	AirVolumeAuto = "auto"
	// AirVolume1 represents volume 1.
	AirVolume1 = "1"
	// AirVolume2 represents volume 2.
	AirVolume2 = "2"
	// AirVolume3 represents volume 3.
	AirVolume3 = "3"
	// AirVolume4 represents volume 4.
	AirVolume4 = "4"
	// AirVolume5 represents volume 5.
	AirVolume5 = "5"
	// AirVolume6 represents volume 6.
	AirVolume6 = "6"
	// AirVolume7 represents volume 7.
	AirVolume7 = "7"
	// AirVolume8 represents volume 8.
	AirVolume8 = "8"
	// AirVolume9 represents volume 9.
	AirVolume9 = "9"
	// AirVolume10 represents volume 10.
	AirVolume10 = "10"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError added in v0.2.0

type APIError struct {
	HTTPStatus int    `json:"-"`
	Code       int    `json:"code"`
	Message    string `json:"message"`
}

APIError is an error from Nature Remo API.

func (*APIError) Error added in v0.2.0

func (err *APIError) Error() string

type AirCon

type AirCon struct {
	Range           *AirConRange    `json:"range"`
	TemperatureUnit TemperatureUnit `json:"tempUnit"`
}

AirCon represents air conditioner.

type AirConRange

type AirConRange struct {
	Modes        map[OperationMode]*AirConRangeMode `json:"modes"`
	FixedButtons []Button                           `json:"fixedButtons"`
}

AirConRange holds range of each setting and buttons of air conditioner.

type AirConRangeMode

type AirConRangeMode struct {
	Temperature  []string       `json:"temp"`
	AirVolume    []AirVolume    `json:"vol"`
	AirDirection []AirDirection `json:"dir"`
}

AirConRangeMode represetns ranges of settings of air conditioner.

type AirConSettings

type AirConSettings struct {
	Temperature   string        `json:"temp"`
	OperationMode OperationMode `json:"mode"`
	AirVolume     AirVolume     `json:"vol"`
	AirDirection  AirDirection  `json:"dir"`
	Button        Button        `json:"button"`
}

AirConSettings represents settings of air conditioner.

type AirDirection

type AirDirection string

AirDirection represents direction of air.

const (
	// AirDirectionAuto represents auto mode.
	AirDirectionAuto AirDirection = ""
)

func (AirDirection) StringValue

func (d AirDirection) StringValue() string

StringValue converts AirDirection to string.

type AirVolume

type AirVolume string

AirVolume represents air volume of air conditioner.

func (AirVolume) StringValue

func (v AirVolume) StringValue() string

StringValue converts AirVolume to string.

type Appliance

type Appliance struct {
	ID             string          `json:"id"`
	Type           ApplianceType   `json:"type"`
	Device         *DeviceCore     `json:"device"`
	Model          *ApplianceModel `json:"model"`
	Nickname       string          `json:"nickname"`
	Image          string          `json:"image"`
	Signals        []*Signal       `json:"signals"`
	AirConSettings *AirConSettings `json:"settings"`
	AirCon         *AirCon         `json:"aircon"`
	TV             *TV             `json:"tv"`
	Light          *Light          `json:"light"`
}

Appliance represents controlable devices with Nature Remo such as air conditioners and TVs.

func (*Appliance) SignalByName

func (a *Appliance) SignalByName(name string) *Signal

SignalByName gets a signal by name from Signals. If there are not any signals which have specified name, SignalByName returns nil.

type ApplianceModel

type ApplianceModel struct {
	ID string `json:"id"`
	// Not in swagger, but actually included in the response
	Country      string `json:"country"`
	Manufacturer string `json:"manufacturer"`
	RemoteName   string `json:"remote_name"`
	Name         string `json:"name"`
	Image        string `json:"image"`
}

ApplianceModel is device information of appliance which is identified by Nature Remo API.

type ApplianceService

type ApplianceService interface {
	// Detect detects air conditioners by an infrared ray signal.
	Detect(ctx context.Context, ir *IRSignal) ([]*DetectedAirCon, error)
	// GetAll gets all appliances.
	GetAll(ctx context.Context) ([]*Appliance, error)
	// New creates new appliance and links to specified device.
	New(ctx context.Context, device *Device, nickname, image string) (*Appliance, error)
	// NewWithModel creates new appliance with specified model.
	NewWithModel(ctx context.Context, device *Device, nickname, image string, model *ApplianceModel) (*Appliance, error)
	// ReOrder arranges appliances by given orders.
	ReOrder(ctx context.Context, appliances []*Appliance) error
	// Delete deletes specified appliance.
	Delete(ctx context.Context, appliance *Appliance) error
	// Update updates specified appliance.
	Update(ctx context.Context, appliance *Appliance) (*Appliance, error)
	// UpdateAirConSettings updates air conditioner settings of specified appliance.
	UpdateAirConSettings(ctx context.Context, appliance *Appliance, settings *AirConSettings) error
	// SendTVSignal sends TV infrared signal.
	SendTVSignal(ctx context.Context, appliance *Appliance, buttonName string) (*TVState, error)
	// SendLightSignal sends light infrared signal.
	SendLightSignal(ctx context.Context, appliance *Appliance, buttonName string) (*LightState, error)
}

ApplianceService provides interface of Nature Remo APIs which are related to appliances.

type ApplianceType

type ApplianceType string

ApplianceType represents type of appliance.

const (
	// ApplianceTypeAirCon represents an air conditioner.
	ApplianceTypeAirCon ApplianceType = "AC"
	// ApplianceTypeTV represents an TV
	ApplianceTypeTV ApplianceType = "TV"
	// ApplianceTypeLight represents Light
	ApplianceTypeLight ApplianceType = "LIGHT"
	// ApplianceTypeIR represents a device which is controlled by infrared.
	ApplianceTypeIR ApplianceType = "IR"
)

type Button

type Button string

Button represents button of air conditioner such as power-off button and power-on button.

const (
	// ButtonPowerOn represents power-on button.
	ButtonPowerOn Button = ""
	// ButtonPowerOff represents power-off button.
	ButtonPowerOff Button = "power-off"
)

func (Button) StringValue

func (b Button) StringValue() string

StringValue converts Button to string.

type Client

type Client struct {
	UserService      UserService
	DeviceService    DeviceService
	ApplianceService ApplianceService
	SignalService    SignalService

	HTTPClient    *http.Client
	AccessToken   string
	BaseURL       string
	UserAgent     string
	LastRateLimit *RateLimit
}

Client is an API client for Nature Remo Cloud API.

func NewClient

func NewClient(accessToken string) *Client

NewClient creates new client with access token of Nature Remo API. You can get access token from https://home.nature.global/.

type DefaultButton added in v0.2.0

type DefaultButton struct {
	Name  string
	Image string
	Label string
}

DefaultButton is defined by Nature.inc? or defined at IRDB?

type DetectedAirCon

type DetectedAirCon struct {
	Model  *ApplianceModel `json:"model"`
	Params *AirConSettings `json:"params"`
}

DetectedAirCon represents information of an air conditioner which is detected by ApplianceService.Detected.

type Device

type Device struct {
	DeviceCore
	// NewestEvents is newest sensor values such as temperature, humidity and illumination.
	NewestEvents map[SensorType]SensorValue `json:"newest_events"`
}

Device represents a device such as Nature Remo and Nature Remo Mini.

type DeviceCore

type DeviceCore struct {
	ID                string    `json:"id"`
	Name              string    `json:"name"`
	TemperatureOffset int64     `json:"temperature_offset"`
	HumidityOffset    int64     `json:"humidity_offset"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
	FirmwareVersion   string    `json:"firmware_version"`
	MacAddress        string    `json:"mac_address"`
	// Not in swagger, but actually included in the response
	BtMacAddress string `json:"bt_mac_address"`
	SerialNumber string `json:"serial_number"`
	// Not in swagger, but actually included in the response
	Users []User `json:"users"`
}

DeviceCore represents core information of a device.

type DeviceService

type DeviceService interface {
	// GetAll gets all information of devices which are related with user.
	GetAll(ctx context.Context) ([]*Device, error)
	// Update updates device information which exclude temperature offset and humidity offset.
	Update(ctx context.Context, device *Device) (*Device, error)
	// Delete deletes specified device.
	Delete(ctx context.Context, device *Device) error
	// UpdateTemperatureOffset updates temperature offset of specified device.
	UpdateTemperatureOffset(ctx context.Context, device *Device) (*Device, error)
	// UpdateHumidityOffset updates humidity offset of specified device.
	UpdateHumidityOffset(ctx context.Context, device *Device) (*Device, error)
}

DeviceService provides interface of Nature Remo APIs which are related to devices.

type IRSignal

type IRSignal struct {
	Freq   int64   `json:"freq"`
	Data   []int64 `json:"data"`
	Format string  `json:"format"`
}

IRSignal describes infrared ray signal.

type Light added in v0.2.0

type Light struct {
	State   *LightState
	Buttons []DefaultButton
}

type LightState added in v0.2.0

type LightState struct {
	Brightness string `json:"brightness"`
	Power      string `json:"power"`
	LastButton string `json:"last_button"`
}

LightState is Light state

type LocalClient

type LocalClient struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func NewLocalClient

func NewLocalClient(addr string) *LocalClient

func (*LocalClient) Emit

func (cli *LocalClient) Emit(ctx context.Context, ir *IRSignal) error

func (*LocalClient) Fetch

func (cli *LocalClient) Fetch(ctx context.Context) (*IRSignal, error)

type OperationMode

type OperationMode string

OperationMode represents a operation mode of air conditioner such as warm and cool.

const (
	// OperationModeAuto represents auto mode.
	OperationModeAuto OperationMode = "auto"
	// OperationModeCool represents cool mode.
	OperationModeCool OperationMode = "cool"
	// OperationModeWarm represents warm mode.
	OperationModeWarm OperationMode = "warm"
	// OperationModeDry represents dry mode.
	OperationModeDry OperationMode = "dry"
	// OperationModeBlow represents blow mode.
	OperationModeBlow OperationMode = "blow"
)

func (OperationMode) StringValue

func (om OperationMode) StringValue() string

StringValue converts OperationMode to string value.

type RateLimit

type RateLimit struct {
	// Limit is a limit of request.
	Limit int64
	// Remaining is remaining request count.
	Remaining int64
	// Reset is time which a limit of request would be reseted.
	Reset time.Time
}

RateLimit has values of X-Rate-Limit-* in the response header.

func RateLimitFromHeader

func RateLimitFromHeader(h http.Header) (*RateLimit, error)

type SensorType

type SensorType string

SensorType represents type of sensor.

const (
	// SensorTypeTemperature represents a temperature sensor.
	SensorTypeTemperature SensorType = "te"
	// SensorTypeHumidity represents a humidity sensor.
	SensorTypeHumidity SensorType = "hu"
	// SensorTypeIllumination represents a illumination sensor.
	SensorTypeIllumination SensorType = "il"
	// SensorTypeMovement represents a movement sensor.
	SensorTypeMovement SensorType = "mo"
)

type SensorValue

type SensorValue struct {
	Value     float64   `json:"val"`
	CreatedAt time.Time `json:"created_at"`
}

SensorValue represents value of sensor.

type Signal

type Signal struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Image string `json:"image"`
}

Signal represents a infrared ray signal related to an appliance.

type SignalService

type SignalService interface {
	// GetAll gets all signals which related to specified appliance.
	GetAll(ctx context.Context, appliance *Appliance) ([]*Signal, error)
	// New creates new signal and links to specified appliance.
	New(ctx context.Context, appliance *Appliance, ir *IRSignal, name, image string) (*Signal, error)
	// ReOrder arranges signals by given orders.
	ReOrder(ctx context.Context, appliance *Appliance, signals []*Signal) error
	// Update updates specified signal.
	Update(ctx context.Context, signal *Signal) (*Signal, error)
	// Delete deletes specified signal.
	Delete(ctx context.Context, signal *Signal) error
	// Send sends specified signal.
	Send(ctx context.Context, signal *Signal) error
}

SignalService provides interface of Nature Remo APIs which are related to signals.

type TV added in v0.2.0

type TV struct {
	State   *TVState
	Buttons []DefaultButton
}

type TVInputType added in v0.2.0

type TVInputType string
const (
	TVInputTypeT  TVInputType = "t"
	TVInputTypeBS TVInputType = "bs"
	TVInputTypeCS TVInputType = "cs"
)

type TVState added in v0.2.0

type TVState struct {
	Input TVInputType `json:"input"`
}

TVState is TV state

type TemperatureUnit

type TemperatureUnit string

TemperatureUnit is unit of temperature.

const (
	// TemperatureUnitAuto represents auto.
	TemperatureUnitAuto TemperatureUnit = ""
	// TemperatureUnitFahrenheit represents fahrenheit.
	TemperatureUnitFahrenheit TemperatureUnit = "f"
	// TemperatureUnitCelsius represents celsius.
	TemperatureUnitCelsius TemperatureUnit = "c"
)

type User

type User struct {
	ID       string `json:"id"`
	Nickname string `json:"nickname"`
}

User represents user data.

type UserService

type UserService interface {
	// Me gets own user data.
	Me(ctx context.Context) (*User, error)
	// Update updates user data.
	Update(ctx context.Context, u *User) (*User, error)
}

UserService provides interface of Nature Remo APIs which are related to user.

Directories

Path Synopsis
_example
airconbot Module

Jump to

Keyboard shortcuts

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