@@ -65,24 +65,14 @@ func (c *Connection) Enable(enable bool) error {
6565
6666// Enabled implements the api.Charger interface
6767func (c * Connection ) Enabled () (bool , error ) {
68- resp , err := c .plug .GetDeviceInfo ()
69- if err != nil {
70- return false , err
71- }
72-
73- return resp .DeviceON , nil
68+ return c .plug .IsOn ()
7469}
7570
7671// CurrentPower provides current power consuption
7772func (c * Connection ) CurrentPower () (float64 , error ) {
7873 resp , err := c .plug .GetEnergyUsage ()
7974 if err != nil {
80- if strings .Contains (err .Error (), "-1001" ) {
81- c .log .DEBUG .Printf ("meter not available" )
82- return 0 , nil
83- } else {
84- return 0 , err
85- }
75+ return 0 , c .checkMeterError (err )
8676 }
8777
8878 return float64 (resp .CurrentPower ) / 1e3 , nil
@@ -92,12 +82,7 @@ func (c *Connection) CurrentPower() (float64, error) {
9282func (c * Connection ) ChargedEnergy () (float64 , error ) {
9383 resp , err := c .plug .GetEnergyUsage ()
9484 if err != nil {
95- if strings .Contains (err .Error (), "-1001" ) {
96- c .log .DEBUG .Printf ("meter not available" )
97- return 0 , nil
98- } else {
99- return 0 , err
100- }
85+ return 0 , c .checkMeterError (err )
10186 }
10287
10388 if int64 (resp .TodayEnergy ) > c .lasttodayenergy {
@@ -107,3 +92,12 @@ func (c *Connection) ChargedEnergy() (float64, error) {
10792
10893 return float64 (c .energy ) / 1000 , nil
10994}
95+
96+ // checkMeterError checks for missing meter error
97+ func (c * Connection ) checkMeterError (err error ) error {
98+ if strings .Contains (err .Error (), "-1001" ) {
99+ return nil
100+ }
101+
102+ return err
103+ }
0 commit comments