yp87/leaf2mqtt

leaf/command/battery update returns invalid value

Closed this issue · 2 comments

Describe the bug
When publishing leaf/command/battery, payload: update, an error is received. This also happens when a general update using leaf/command, payload: update is sent. Seems to be affecting other values being returned, with the exception of climate.

Invalid value: Not in inclusive range 0..3: 4

LEAF_TYPE
newerThanMay2019

Expected behavior
Battery and other values should be updated. Currently only climate values are being returned.

Add-on version: 45
System: Home Assistant OS 9.5 (aarch64 / raspberrypi4-64)
Home Assistant Core: 2023.3.6
Home Assistant Supervisor: 2023.03.3

Log (VIN removed)
FINEST: 2023-04-04 09:06:47.678976: MqttClientWrapper: Publishing message SJNxxxxx/cockpitStatus/lastReceivedDateTimeUtc 2023-04-04T08:06:47.676075Z
FINEST: 2023-04-04 09:06:47.679096: MqttClientWrapper: Publishing message SJNxxxxx/cockpitStatus/json {"totalMileage":"7985","lastReceivedDateTimeUtc":"2023-04-04T08:06:47.676075Z"}
FINEST: 2023-04-04 09:06:47.679209: MqttClientWrapper: Publishing message SJNxxxxx/cockpit/totalMileage 7985
FINEST: 2023-04-04 09:06:47.679281: MqttClientWrapper: Publishing message SJNxxxxx/cockpit/lastReceivedDateTimeUtc 2023-04-04T08:06:47.676075Z
FINEST: 2023-04-04 09:06:47.679555: MqttClientWrapper: Publishing message SJNxxxxx/cockpit/json {"totalMileage":"7985","lastReceivedDateTimeUtc":"2023-04-04T08:06:47.676075Z"}
FINEST: 2023-04-04 09:06:47.704935: main: publishStates {location/latitude: 53.xxxx, location/longitude: -1.8xxxx, location/lastReceivedDateTimeUtc: 2023-04-04T08:06:47.704828Z, location/json: {"latitude":"53.xxxx","longitude":"-1.8xxxx","lastReceivedDateTimeUtc":"2023-04-04T08:06:47.704828Z"}, SJNxxxxx/location/latitude: 53.xxxx, SJNxxxxx/location/longitude: -1.8xxx, SJNxxxxx/location/lastReceivedDateTimeUtc: 2023-04-04T08:06:47.704828Z, SJNxxxxx/location/json: {"latitude":"53.6xxxx","longitude":"-1.8xxxx","lastReceivedDateTimeUtc":"2023-04-04T08:06:47.704828Z"}}
FINEST: 2023-04-04 09:06:47.705468: MqttClientWrapper: Publishing message location/latitude 53.xxxx
FINEST: 2023-04-04 09:06:47.706243: MqttClientWrapper: Publishing message location/longitude -1.8xxxx
FINEST: 2023-04-04 09:06:47.707250: MqttClientWrapper: Publishing message location/lastReceivedDateTimeUtc 2023-04-04T08:06:47.704828Z
FINEST: 2023-04-04 09:06:47.708474: MqttClientWrapper: Publishing message location/json {"latitude":"53.6xxxxx","longitude":"-1.8xxxxx","lastReceivedDateTimeUtc":"2023-04-04T08:06:47.704828Z"}
FINEST: 2023-04-04 09:06:47.709692: MqttClientWrapper: Publishing message SJNxxxxx/location/latitude 53.xxxx
FINEST: 2023-04-04 09:06:47.710929: MqttClientWrapper: Publishing message SJNxxxxx/location/longitude -1.xxxx
FINEST: 2023-04-04 09:06:47.712081: MqttClientWrapper: Publishing message SJNxxxxx/location/lastReceivedDateTimeUtc 2023-04-04T08:06:47.704828Z
FINEST: 2023-04-04 09:06:47.712418: MqttClientWrapper: Publishing message SJNxxxxx/location/json {"latitude":"53.6xxxx","longitude":"-1.8xxxxx","lastReceivedDateTimeUtc":"2023-04-04T08:06:47.704828Z"}
FINEST: 2023-04-04 09:06:48.363805: main: publishStates {climate/cabinTemperatureC: 3.5, climate/cabinTemperatureF: 38.3, climate/RunningStatus: false, climate/runningStatus: false, climate/lastReceivedDateTimeUtc: 2023-04-04T08:06:48.363635Z, climate/json: {"cabinTemperatureC":"3.5","cabinTemperatureF":"38.3","RunningStatus":"false","runningStatus":"false","lastReceivedDateTimeUtc":"2023-04-04T08:06:48.363635Z"}, SJNxxxxx/climate/cabinTemperatureC: 3.5, SJNxxxxx/climate/cabinTemperatureF: 38.3, SJNxxxxx/climate/RunningStatus: false, SJNxxxxx/climate/runningStatus: false, SJNxxxxx/climate/lastReceivedDateTimeUtc: 2023-04-04T08:06:48.363635Z, SJNxxxxx/climate/json: {"cabinTemperatureC":"3.5","cabinTemperatureF":"38.3","RunningStatus":"false","runningStatus":"false","lastReceivedDateTimeUtc":"2023-04-04T08:06:48.363635Z"}}
FINEST: 2023-04-04 09:06:48.364062: MqttClientWrapper: Publishing message climate/cabinTemperatureC 3.5
FINEST: 2023-04-04 09:06:48.366240: MqttClientWrapper: Publishing message climate/cabinTemperatureF 38.3
FINEST: 2023-04-04 09:06:48.368451: MqttClientWrapper: Publishing message climate/RunningStatus false
FINEST: 2023-04-04 09:06:48.370833: MqttClientWrapper: Publishing message climate/runningStatus false
FINEST: 2023-04-04 09:06:48.372707: MqttClientWrapper: Publishing message climate/lastReceivedDateTimeUtc 2023-04-04T08:06:48.363635Z
FINEST: 2023-04-04 09:06:48.374786: MqttClientWrapper: Publishing message climate/json {"cabinTemperatureC":"3.5","cabinTemperatureF":"38.3","RunningStatus":"false","runningStatus":"false","lastReceivedDateTimeUtc":"2023-04-04T08:06:48.363635Z"}
FINEST: 2023-04-04 09:06:48.376026: MqttClientWrapper: Publishing message SJNxxxxx/climate/cabinTemperatureC 3.5
FINEST: 2023-04-04 09:06:48.377581: MqttClientWrapper: Publishing message SJNxxxxx/climate/cabinTemperatureF 38.3
FINEST: 2023-04-04 09:06:48.378772: MqttClientWrapper: Publishing message SJNxxxxx/climate/RunningStatus false
FINEST: 2023-04-04 09:06:48.379930: MqttClientWrapper: Publishing message SJNxxxxx/climate/runningStatus false
FINEST: 2023-04-04 09:06:48.380822: MqttClientWrapper: Publishing message SJNxxxxx/climate/lastReceivedDateTimeUtc 2023-04-04T08:06:48.363635Z
FINEST: 2023-04-04 09:06:48.381900: MqttClientWrapper: Publishing message SJNxxxxx/climate/json {"cabinTemperatureC":"3.5","cabinTemperatureF":"38.3","RunningStatus":"false","runningStatus":"false","lastReceivedDateTimeUtc":"2023-04-04T08:06:48.363635Z"}
FINEST: 2023-04-04 09:06:49.560590: LeafSession: Executing
FINE: 2023-04-04 09:06:50.039086: LeafSession: RangeError (length): Invalid value: Not in inclusive range 0..3: 4
FINER: 2023-04-04 09:06:50.039668: LeafSession: #0 new NissanConnectBattery (package:dartnissanconnect/src/nissanconnect_battery.dart)
#1 NissanConnectVehicle.requestBatteryStatus (package:dartnissanconnect/src/nissanconnect_vehicle.dart:53)

#2 NissanConnectVehicleWrapper.fetchBatteryStatus (file:///app/src/leaf/nissan_connect_wrapper.dart:69)

#3 LeafSession._executeWithRetry (file:///app/src/leaf/leaf_session.dart:153)

#4 LeafSession.executeWithRetry (file:///app/src/leaf/leaf_session.dart:129)

#5 Future.wait. (dart:async/future.dart:522)

#6 startUpdateLoop (file:///app/src/leaf_2_mqtt.dart:111)

#7 Future.wait. (dart:async/future.dart:522)

#8 main (file:///app/src/leaf_2_mqtt.dart:69)

FINE: 2023-04-04 09:06:50.040054: LeafSession: Exception: Execution failed.
FINER: 2023-04-04 09:06:50.040413: LeafSession: #0 LeafSession._executeWithRetry (file:///app/src/leaf/leaf_session.dart:161)

#1 LeafSession.executeWithRetry (file:///app/src/leaf/leaf_session.dart:129)

#2 Future.wait. (dart:async/future.dart:522)

#3 startUpdateLoop (file:///app/src/leaf_2_mqtt.dart:111)

#4 Future.wait. (dart:async/future.dart:522)

#5 main (file:///app/src/leaf_2_mqtt.dart:69)

WARNING: 2023-04-04 09:06:50.040624: main: Could not execute request.
FINEST: 2023-04-04 09:06:50.040834: MqttClientWrapper: Publishing message lastErrorDateTimeUtc 2023-04-04T08:06:50.040815Z
FINEST: 2023-04-04 09:06:50.043512: MqttClientWrapper: Publishing message {vin}/lastErrorDateTimeUtc 2023-04-04T08:06:50.040815Z
FINER: 2023-04-04 09:09:08.847883: MqttClientWrapper: Received data: leaf/command/battery update
FINER: 2023-04-04 09:09:08.847952: main: fetchAndPublishBatteryStatus for SJNxxxxx
FINEST: 2023-04-04 09:09:08.847986: LeafSession: Executing
FINE: 2023-04-04 09:09:09.247101: LeafSession: RangeError (length): Invalid value: Not in inclusive range 0..3: 4
FINER: 2023-04-04 09:09:09.247324: LeafSession: #0 new NissanConnectBattery (package:dartnissanconnect/src/nissanconnect_battery.dart)
#1 NissanConnectVehicle.requestBatteryStatus (package:dartnissanconnect/src/nissanconnect_vehicle.dart:53)

#2 NissanConnectVehicleWrapper.fetchBatteryStatus (file:///app/src/leaf/nissan_connect_wrapper.dart:69)

#3 LeafSession._executeWithRetry (file:///app/src/leaf/leaf_session.dart:153)

#4 LeafSession.executeWithRetry (file:///app/src/leaf/leaf_session.dart:129)

FINER: 2023-04-04 09:09:09.247369: LeafSession: Force a login before retrying failed execution.
FINEST: 2023-04-04 09:09:11.677639: LeafSession: Executing
FINE: 2023-04-04 09:09:12.073721: LeafSession: RangeError (length): Invalid value: Not in inclusive range 0..3: 4
FINER: 2023-04-04 09:09:12.074922: LeafSession: #0 new NissanConnectBattery (package:dartnissanconnect/src/nissanconnect_battery.dart)
#1 NissanConnectVehicle.requestBatteryStatus (package:dartnissanconnect/src/nissanconnect_vehicle.dart:53)

#2 NissanConnectVehicleWrapper.fetchBatteryStatus (file:///app/src/leaf/nissan_connect_wrapper.dart:69)

#3 LeafSession._executeWithRetry (file:///app/src/leaf/leaf_session.dart:153)

#4 LeafSession.executeWithRetry (file:///app/src/leaf/leaf_session.dart:129)

FINE: 2023-04-04 09:09:12.076565: LeafSession: Exception: Execution failed.
FINER: 2023-04-04 09:09:12.076714: LeafSession: #0 LeafSession._executeWithRetry (file:///app/src/leaf/leaf_session.dart:161)

#1 LeafSession.executeWithRetry (file:///app/src/leaf/leaf_session.dart:129)

WARNING: 2023-04-04 09:09:12.076754: main: Could not execute request.
FINEST: 2023-04-04 09:09:12.076794: MqttClientWrapper: Publishing message lastErrorDateTimeUtc 2023-04-04T08:09:12.076780Z
FINEST: 2023-04-04 09:09:12.077348: MqttClientWrapper: Publishing message {vin}/lastErrorDateTimeUtc 2023-04-04T08:09:12.076780Z

The issue seems to be when the battery is exactly 100%. As soon as the battery reduced to <100% the missing values started to reappear. Is the % considered as part of the string, increasing the length from 3 (0-99%), to 4 (100%).

yp87 commented

Looks like the issue comes from the My Leaf libraries. Try to repro with the My Leaf app and contact the owner if you can reproduce.