Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) GetDevice(ctx context.Context) (DeviceResponse, error)
- func (c *Client) GetMeterReading(ctx context.Context) (MeterReadingResponse, error)
- func (c *Client) GetPhaseReading(ctx context.Context) (PhaseReadingResponse, error)
- func (c *Client) GetReport(ctx context.Context, u Utility, i Interval, p uint) (Report, error)
- func (c *Client) With(opts ...Option) error
- type Config
- type DeviceResponse
- type Interval
- type Logger
- type MeterReadingResponse
- type Option
- type PhaseReadingResponse
- type Report
- type TimedValue
- type UnexpectedResponseError
- type Unit
- type UnsupportedIntervalError
- type Utility
Constants ¶
const ( AttrDeviceMAC = "youless.device.mac" AttrDeviceModel = "youless.device.model" AttrDeviceFirmware = "youless.device.firmware" ErrPasswordRequired = "password required" ErrInvalidPassword = "invalid password" )
const ( ErrInvalidBaseURL errors.Msg = "invalid base url" ConfigValidationError errors.Kind = "config validation error" )
const DateTimeLayout = "0601021504"
const OptionError errors.Kind = "option error"
const ReportTimeLayout = "2006-01-02T15:04:05"
const TracerName string = "youless-client"
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 (*Client) GetMeterReading ¶
func (c *Client) GetMeterReading(ctx context.Context) (MeterReadingResponse, error)
func (*Client) GetPhaseReading ¶
func (c *Client) GetPhaseReading(ctx context.Context) (PhaseReadingResponse, error)
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.
type DeviceResponse ¶
type 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 ¶
func WithDefaultTracerProvider ¶
func WithDefaultTracerProvider() Option
func WithHttpClient ¶
WithHttpClient sets the underlying http.Client for the client.
func WithLogger ¶
func WithTracer ¶
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) TimedValues ¶
func (r Report) TimedValues() ([]TimedValue, error)
type TimedValue ¶
func (TimedValue) String ¶
func (tv TimedValue) String() string
type UnexpectedResponseError ¶
type UnexpectedResponseError struct {
StatusCode int
}
func (*UnexpectedResponseError) Error ¶
func (e *UnexpectedResponseError) Error() string
type UnsupportedIntervalError ¶
func (UnsupportedIntervalError) Error ¶
func (e UnsupportedIntervalError) Error() string