youless

package module
v0.0.0-...-c9cf6f6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-3-Clause Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	AttrDeviceMAC      = "youless.device.mac"
	AttrDeviceModel    = "youless.device.model"
	AttrDeviceFirmware = "youless.device.firmware"

	ErrPasswordRequired = "password required"
	ErrInvalidPassword  = "invalid password"
)
View Source
const (
	ErrInvalidBaseURL errors.Msg = "invalid base url"

	ConfigValidationError errors.Kind = "config validation error"
)
View Source
const DateTimeLayout = "0601021504"
View Source
const OptionError errors.Kind = "option error"
View Source
const ReportTimeLayout = "2006-01-02T15:04:05"
View Source
const TracerName string = "youless-client"
View Source
const Version = "0.0.1"

Version of the package.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config
	// contains filtered or unexported fields
}

Client connects with the Youless device and is able to read logged values. Its zero value is ready to be used once BaseURL is set. By default, it uses a default http.Client, which can be overridden via WithHTTPClient.

func NewClient

func NewClient(conf Config, opts ...Option) (*Client, error)

NewClient creates a new Client with Config and applies any provided Option(s).

func (*Client) GetDevice

func (c *Client) GetDevice(ctx context.Context) (DeviceResponse, error)

func (*Client) GetMeterReading

func (c *Client) GetMeterReading(ctx context.Context) (MeterReadingResponse, error)

func (*Client) GetPhaseReading

func (c *Client) GetPhaseReading(ctx context.Context) (PhaseReadingResponse, error)

func (*Client) GetReport

func (c *Client) GetReport(ctx context.Context, u Utility, i Interval, p uint) (Report, error)

func (*Client) With

func (c *Client) With(opts ...Option) error

With applies the provided Option(s) to the Client.

type Config

type Config struct {
	// BaseURL of the device.
	BaseURL string `json:"base_url" yaml:"baseUrl" default:"http://youless"`
	// Name of the device, is optional and used for logging/debugging.
	Name string `json:"name" yaml:"name" default:"YouLess"`
	// Timeout specifies a time limit for requests made by the http.Client used
	// by Client.
	Timeout time.Duration `json:"timeout" yaml:"timeout" default:"5s"`
	// Password used to connect with the device.
	Password string `json:"password" yaml:"password"`
	// PasswordFile contains the password used to connect with the device. When
	// both Password and PasswordFile are set, PasswordFile takes precedence.
	PasswordFile string `json:"password_file" yaml:"passwordFile"`
}

Config is the configuration for a Client. It can be unmarshalled from json, yaml, env or flag values.

func (Config) Validate

func (c Config) Validate() error

type DeviceResponse

type DeviceResponse struct {
	Model    string `json:"model"`
	Firmware string `json:"fw"`
	MAC      string `json:"mac"`
}

type Interval

type Interval uint32
const (
	PerMin   Interval = 60
	Per10min Interval = 600
	PerHour  Interval = 3600
	PerDay   Interval = 86400
)

func (Interval) Delta

func (i Interval) Delta() uint32

func (Interval) Duration

func (i Interval) Duration() time.Duration

func (Interval) Param

func (i Interval) Param() rune

func (Interval) String

func (i Interval) String() string

type Logger

type Logger interface {
	Request(ctx context.Context, clientName, url string, shared bool)
	FetchedCookie(clientName string, cookie http.Cookie)
}

func NewLogger

func NewLogger(zl zerolog.Logger) Logger

func NopLogger

func NopLogger() Logger

type MeterReadingResponse

type MeterReadingResponse struct {
	// Timestamp is a unix timestamp of the last meter reading.
	Timestamp int64 `json:"tm"`
	// ElectricityImport1 is the meter reading of total imported low tariff
	// electricity in kWh (Import 1).
	ElectricityImport1 float64 `json:"p1"`
	// ElectricityImport2 is the meter reading of total imported high tariff
	// electricity in kWh (Import 2).
	ElectricityImport2 float64 `json:"p2"`
	// ElectricityExport1 is the meter reading of total exported low tariff
	// electricity in kWh (Export 1).
	ElectricityExport1 float64 `json:"n1"`
	// ElectricityExport2 is the meter reading of total exported high tariff
	// electricity in kWh (Export 2).
	ElectricityExport2 float64 `json:"n2"`
	// NetElectricity is the total measured electricity which equals
	// (ElectricityImport1 + ElectricityImport2 - ElectricityExport1 - ElectricityExport2)
	// (Meterstand).
	NetElectricity float64 `json:"net"`
	// Power is the current imported (or negative for exported) electricity
	// power in Watt (Actueel vermogen).
	Power int64 `json:"pwr"`

	// S0Timestamp is a unix timestamp of the last S0 reading.
	S0Timestamp int64 `json:"ts0"`
	// S0Total is the total power in kWh measured by the S0 meter
	// (S0 meterstand).
	S0Total float64 `json:"cs0"`
	// S0 is the current electricity power measured in Watt from the S0 meter
	// (S0 vermogen).
	S0 int64 `json:"ps0"`

	// GasTimestamp is a timestamp in format YYMMDDHHmm of the last gas meter
	// reading.
	GasTimestamp uint64 `json:"gts"`
	// Gas is the meter reading of delivered gas (in m3) to client.
	Gas float64 `json:"gas"`

	// WaterTimestamp is a timestamp in format YYMMDDHHmm of the last water meter
	// reading.
	WaterTimestamp uint64 `json:"wts"`
	// Water is the meter reading of delivered water (in m3) to client.
	Water float64 `json:"wtr"`
}

MeterReadingResponse is the response from the /e endpoint. It is a translation of a P1 telegram, with addition values, to JSON. https://www.netbeheernederland.nl/_upload/Files/Slimme_meter_15_32ffe3cc38.pdf

func (MeterReadingResponse) GasTime

func (res MeterReadingResponse) GasTime() time.Time

func (MeterReadingResponse) S0Time

func (res MeterReadingResponse) S0Time() time.Time

func (MeterReadingResponse) Time

func (res MeterReadingResponse) Time() time.Time

func (MeterReadingResponse) WaterTime

func (res MeterReadingResponse) WaterTime() time.Time

type Option

type Option func(c *Client) error

func WithDefaultTracerProvider

func WithDefaultTracerProvider() Option

func WithHttpClient

func WithHttpClient(client http.Client) Option

WithHttpClient sets the underlying http.Client for the client.

func WithLogger

func WithLogger(l Logger) Option

func WithTracer

func WithTracer(t trace.Tracer) Option

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider sets a new tracer for the client from the specified tracer provider.

type PhaseReadingResponse

type PhaseReadingResponse struct {
	// Tariff is the current tariff (Tarief).
	Tariff uint8 `json:"tr"`

	// Current1 is the current imported electricity current in Ampere on phase 1
	// (Stroom L1).
	Current1 float64 `json:"i1"`
	// Current2 is the current imported electricity current in Ampere on phase 2
	// (Stroom L2).
	Current2 float64 `json:"i2"`
	// Current3 is the current imported electricity current in Ampere on phase 3
	// (Stroom L3).
	Current3 float64 `json:"i3"`

	// Power1 is the current imported electricity power in Watt on phase 1
	// (Vermogen L1).
	Power1 int64 `json:"l1"`
	// Power2 is the current imported electricity power in Watt on phase 2
	// (Vermogen L2).
	Power2 int64 `json:"l2"`
	// Power3 is the current imported electricity power in Watt on phase 3
	// (Vermogen L3).
	Power3 int64 `json:"l3"`

	// Voltage1 is the current voltage on phase 1 (Spanning L1).
	Voltage1 float64 `json:"v1"`
	// Voltage2 is the current voltage on phase 2 (Spanning L2).
	Voltage2 float64 `json:"v2"`
	// Voltage3 is the current voltage on phase 3 (Spanning L3).
	Voltage3 float64 `json:"v3"`
}

https://community.home-assistant.io/t/youless-sensors-for-detailed-information-per-phase/433419 https://domoticx.com/p1-poort-slimme-meter-hardware/

type Report

type Report struct {
	Unit      Unit     `json:"un"`
	Timestamp string   `json:"tm"`
	Interval  Interval `json:"dt"`
	RawValues []string `json:"val"`
}

func (Report) Time

func (r Report) Time() time.Time

func (Report) TimeOfValue

func (r Report) TimeOfValue(i uint) time.Time

func (Report) TimedValues

func (r Report) TimedValues() ([]TimedValue, error)

type TimedValue

type TimedValue struct {
	Time     time.Time
	Value    uint64
	Inactive bool
}

func (TimedValue) String

func (tv TimedValue) String() string

type UnexpectedResponseError

type UnexpectedResponseError struct {
	StatusCode int
}

func (*UnexpectedResponseError) Error

func (e *UnexpectedResponseError) Error() string

type Unit

type Unit string
const (
	Watt       Unit = "Watt"
	KiloWatt   Unit = "kWh"
	Liter      Unit = "L"
	CubicMeter Unit = "m3"
)

type UnsupportedIntervalError

type UnsupportedIntervalError struct {
	Utility  Utility
	Interval Interval
}

func (UnsupportedIntervalError) Error

func (e UnsupportedIntervalError) Error() string

type Utility

type Utility string
const (
	Power Utility = "power"
	Gas   Utility = "gas"
	Water Utility = "water"
	S0    Utility = "s0"
)

func (Utility) Endpoint

func (s Utility) Endpoint() string

func (Utility) String

func (s Utility) String() string

Jump to

Keyboard shortcuts

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