Easee: check phase mode on startup (#1598)

This commit is contained in:
andig 2021-09-20 13:12:39 +02:00 • committed by GitHub
parent 327cf49ec6
commit 9c5b192c0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 117 additions and 94 deletions

View file

@ -95,14 +95,6 @@ func NewEasee(user, password, charger string, circuit int, cache time.Duration)
Base: c.Client.Transport,
}
// find site
site, err := c.chargerDetails()
if err != nil {
return c, err
}
c.site = site.ID
// find charger
if charger == "" {
chargers, err := c.chargers()
@ -117,6 +109,14 @@ func NewEasee(user, password, charger string, circuit int, cache time.Duration)
c.charger = chargers[0].ID
}
// find site
site, err := c.chargerDetails(c.charger)
if err != nil {
return c, err
}
c.site = site.ID
// find circuit
if circuit == 0 {
if len(site.Circuits) != 1 {
@ -126,6 +126,12 @@ func NewEasee(user, password, charger string, circuit int, cache time.Duration)
c.circuit = site.Circuits[0].ID
}
// verify charger config
config, err := c.chargerConfig(c.charger)
if err == nil && config.PhaseMode != 2 {
c.log.WARN.Println("expected PhaseMode auto- switching phases will NOT work")
}
return c, err
}
@ -140,8 +146,19 @@ func (c *Easee) chargers() (res []easee.Charger, err error) {
return res, err
}
func (c *Easee) chargerDetails() (res easee.Site, err error) {
uri := fmt.Sprintf("%s/chargers/%s/site", easee.API, c.charger)
func (c *Easee) chargerConfig(charger string) (res easee.ChargerConfig, err error) {
uri := fmt.Sprintf("%s/chargers/%s/config", easee.API, charger)
req, err := request.New(http.MethodGet, uri, nil, request.JSONEncoding)
if err == nil {
err = c.DoJSON(req, &res)
}
return res, err
}
func (c *Easee) chargerDetails(charger string) (res easee.Site, err error) {
uri := fmt.Sprintf("%s/chargers/%s/site", easee.API, charger)
req, err := request.New(http.MethodGet, uri, nil, request.JSONEncoding)
if err == nil {

View file

@ -16,102 +16,108 @@ const (
// Charger is the charger type
type Charger struct {
ID string `json:"id"`
Name string `json:"name"`
ID string
Name string
}
type ChargerConfig struct {
IsEnabled bool
LockCablePermanently bool
AuthorizationRequired bool
RemoteStartRequired bool
SmartButtonEnabled bool
WiFiSSID string
DetectedPowerGridType int
OfflineChargingMode int
CircuitMaxCurrentP1 int
CircuitMaxCurrentP2 int
CircuitMaxCurrentP3 int
EnableIdleCurrent bool
LimitToSinglePhaseCharging bool
PhaseMode int
LocalNodeType int
LocalAuthorizationRequired bool
LocalRadioChannel int
LocalShortAddress int
LocalParentAddrOrNumOfNodes int
LocalPreAuthorizeEnabled bool
LocalAuthorizeOfflineEnabled bool
AllowOfflineTxForUnknownId bool
MaxChargerCurrent int
LedStripBrightness int
}
// Site is the site type
type Site struct {
ID int `json:"id"`
SiteKey string `json:"siteKey"`
Name string `json:"name"`
Circuits []Circuit `json:"circuits"`
ID int
SiteKey string
Name string
Circuits []Circuit
}
// Circuit is the circuit type
type Circuit struct {
ID int `json:"id"`
SiteID int `json:"siteId"`
CircuitPanelID int `json:"circuitPanelId"`
PanelName string `json:"panelName"`
RatedCurrent float64 `json:"ratedCurrent"`
UseDynamicMaster bool `json:"useDynamicMaster"`
ParentCircuitID int `json:"parentCircuitId"`
// "chargers": [{
// "id": "string",
// "name": "string",
// "color": 1,
// "createdOn": "2021-01-19T12:39:10.359Z",
// "updatedOn": "2021-01-19T12:39:10.359Z",
// "backPlate": {
// "id": "string",
// "masterBackPlateId": "string",
// "name": "string"
// },
// "levelOfAccess": 1,
// "productCode": 1,
// "userRole": 1,
// "isTemporary": true
// }],
// "masterBackplate": {
// "id": "string",
// "masterBackPlateId": "string",
// "name": "string"
// },
ID int
SiteID int
CircuitPanelID int
PanelName string
RatedCurrent float64
UseDynamicMaster bool
ParentCircuitID int
}
// ChargerStatus is the charger status type
type ChargerStatus struct {
SmartCharging bool `json:"smartCharging"`
CableLocked bool `json:"cableLocked"`
ChargerOpMode int `json:"chargerOpMode"`
TotalPower float64 `json:"totalPower"`
SessionEnergy float64 `json:"sessionEnergy"`
EnergyPerHour float64 `json:"energyPerHour"`
WiFiRSSI int `json:"wiFiRSSI"`
CellRSSI int `json:"cellRSSI"`
LocalRSSI int `json:"localRSSI"`
OutputPhase int `json:"outputPhase"`
DynamicCircuitCurrentP1 float64 `json:"dynamicCircuitCurrentP1"`
DynamicCircuitCurrentP2 float64 `json:"dynamicCircuitCurrentP2"`
DynamicCircuitCurrentP3 float64 `json:"dynamicCircuitCurrentP3"`
LatestPulse string `json:"latestPulse"`
ChargerFirmware int `json:"chargerFirmware"`
LatestFirmware int `json:"latestFirmware"`
Voltage float64 `json:"voltage"`
ChargerRAT int `json:"chargerRAT"`
LockCablePermanently bool `json:"lockCablePermanently"`
InCurrentT2 float64 `json:"inCurrentT2"`
InCurrentT3 float64 `json:"inCurrentT3"`
InCurrentT4 float64 `json:"inCurrentT4"`
InCurrentT5 float64 `json:"inCurrentT5"`
OutputCurrent float64 `json:"outputCurrent"`
IsOnline bool `json:"isOnline"`
InVoltageT1T2 float64 `json:"inVoltageT1T2"`
InVoltageT1T3 float64 `json:"inVoltageT1T3"`
InVoltageT1T4 float64 `json:"inVoltageT1T4"`
InVoltageT1T5 float64 `json:"inVoltageT1T5"`
InVoltageT2T3 float64 `json:"inVoltageT2T3"`
InVoltageT2T4 float64 `json:"inVoltageT2T4"`
InVoltageT2T5 float64 `json:"inVoltageT2T5"`
InVoltageT3T4 float64 `json:"inVoltageT3T4"`
InVoltageT3T5 float64 `json:"inVoltageT3T5"`
InVoltageT4T5 float64 `json:"inVoltageT4T5"`
LedMode int `json:"ledMode"`
CableRating float64 `json:"cableRating"`
DynamicChargerCurrent float64 `json:"dynamicChargerCurrent"`
CircuitTotalAllocatedPhaseConductorCurrentL1 float64 `json:"circuitTotalAllocatedPhaseConductorCurrentL1"`
CircuitTotalAllocatedPhaseConductorCurrentL2 float64 `json:"circuitTotalAllocatedPhaseConductorCurrentL2"`
CircuitTotalAllocatedPhaseConductorCurrentL3 float64 `json:"circuitTotalAllocatedPhaseConductorCurrentL3"`
CircuitTotalPhaseConductorCurrentL1 float64 `json:"circuitTotalPhaseConductorCurrentL1"`
CircuitTotalPhaseConductorCurrentL2 float64 `json:"circuitTotalPhaseConductorCurrentL2"`
CircuitTotalPhaseConductorCurrentL3 float64 `json:"circuitTotalPhaseConductorCurrentL3"`
ReasonForNoCurrent int `json:"reasonForNoCurrent"`
WiFiAPEnabled bool `json:"wiFiAPEnabled"`
LifetimeEnergy float64 `json:"lifetimeEnergy"`
OfflineMaxCircuitCurrentP1 int `json:"offlineMaxCircuitCurrentP1"`
OfflineMaxCircuitCurrentP2 int `json:"offlineMaxCircuitCurrentP2"`
OfflineMaxCircuitCurrentP3 int `json:"offlineMaxCircuitCurrentP3"`
SmartCharging bool
CableLocked bool
ChargerOpMode int
TotalPower float64
SessionEnergy float64
EnergyPerHour float64
WiFiRSSI int
CellRSSI int
LocalRSSI int
OutputPhase int
DynamicCircuitCurrentP1 float64
DynamicCircuitCurrentP2 float64
DynamicCircuitCurrentP3 float64
LatestPulse string
ChargerFirmware int
LatestFirmware int
Voltage float64
ChargerRAT int
LockCablePermanently bool
InCurrentT2 float64
InCurrentT3 float64
InCurrentT4 float64
InCurrentT5 float64
OutputCurrent float64
IsOnline bool
InVoltageT1T2 float64
InVoltageT1T3 float64
InVoltageT1T4 float64
InVoltageT1T5 float64
InVoltageT2T3 float64
InVoltageT2T4 float64
InVoltageT2T5 float64
InVoltageT3T4 float64
InVoltageT3T5 float64
InVoltageT4T5 float64
LedMode int
CableRating float64
DynamicChargerCurrent float64
CircuitTotalAllocatedPhaseConductorCurrentL1 float64
CircuitTotalAllocatedPhaseConductorCurrentL2 float64
CircuitTotalAllocatedPhaseConductorCurrentL3 float64
CircuitTotalPhaseConductorCurrentL1 float64
CircuitTotalPhaseConductorCurrentL2 float64
CircuitTotalPhaseConductorCurrentL3 float64
ReasonForNoCurrent int
WiFiAPEnabled bool
LifetimeEnergy float64
OfflineMaxCircuitCurrentP1 int
OfflineMaxCircuitCurrentP2 int
OfflineMaxCircuitCurrentP3 int
}
// ChargerSettings is the charger settings type