skodaconnect / myskoda

Python library for interacting with MySkoda APIs.
MIT License
9 stars 22 forks source link

Enyaq: Error when querying "get_charging" and charing cable is connected but stopped #74

Closed scoutice closed 1 month ago

scoutice commented 1 month ago

following error happens, when my enyaq is connected to the charging cable, but the wallbox does not delivery any power (e.g. when doing overflow-charging by my PV and there is no sun)

Failed to load data from url /v1/charging/xxxxxxxxxxxxxx. Return value was '{"isVehicleInSavedLocation":false,"status":{"chargingRateInKilometersPerHour":0.0,"chargePowerInKw":0.0,"remainingTimeToFullyChargedInMinutes":0,"battery":{"remainingCruisingRangeInMeters":192000,"stateOfChargeInPercent":45}},"settings":{"targetStateOfChargeInPercent":80,"preferredChargeMode":"MANUAL","availableChargeModes":["MANUAL"],"chargingCareMode":"DEACTIVATED","autoUnlockPlugWhenCharged":"OFF","maxChargeCurrentAc":"REDUCED","batterySupport":"DISABLED"},"carCapturedTimestamp":"2024-10-02T22:00:21Z","errors":[{"type":"STATUS_OF_CHARGING_NOT_AVAILABLE","description":"Status of charging is not available."}]}' Traceback (most recent call last): File "", line 24, in mashumaro_from_json File "", line 14, in __mashumaro_from_dict_json__ mashumaro.exceptions.MissingField: Field "state" of type ChargingState is missing in ChargingStatus instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/admin/.local/lib/python3.12/site-packages/myskoda/rest_api.py", line 41, in _make_get_request data = deserialize(response_text) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 26, in mashumaro_from_json mashumaro.exceptions.InvalidFieldValue: Field "status" of type Optional[ChargingStatus] in Charging has invalid value {'chargingRateInKilometersPerHour': 0.0, 'chargePowerInKw': 0.0, 'remainingTimeToFullyChargedInMinutes': 0, 'battery': {'remainingCruisingRangeInMeters': 192000, 'stateOfChargeInPercent': 45}} Traceback (most recent call last): File "", line 24, in mashumaro_from_json File "", line 14, in __mashumaro_from_dict_json__ mashumaro.exceptions.MissingField: Field "state" of type ChargingState is missing in ChargingStatus instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/admin/Java/myskoda/myskoda_get_all_info.py", line 114, in loop.run_until_complete(main()) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/admin/Java/myskoda/myskoda_get_all_info.py", line 63, in main charging: Charging = await myskoda.get_charging(VIN) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin/.local/lib/python3.12/site-packages/myskoda/myskoda.py", line 163, in get_charging return await self.rest_api.get_charging(vin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin/.local/lib/python3.12/site-packages/myskoda/rest_api.py", line 59, in get_charging return await self._make_get_request(f"/v1/charging/{vin}", Charging.from_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin/.local/lib/python3.12/site-packages/myskoda/rest_api.py", line 41, in _make_get_request data = deserialize(response_text) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 26, in mashumaro_from_json mashumaro.exceptions.InvalidFieldValue: Field "status" of type Optional[ChargingStatus] in Charging has invalid value {'chargingRateInKilometersPerHour': 0.0, 'chargePowerInKw': 0.0, 'remainingTimeToFullyChargedInMinutes': 0, 'battery': {'remainingCruisingRangeInMeters': 192000, 'stateOfChargeInPercent': 45}} Unclosed client session client_session: <aiohttp.client.ClientSession object at 0xf5bc6120> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0xf5bdf660>, 892192.536381557)]', '[(<aiohttp.client_proto.ResponseHandler object at 0xf5bdfcc0>, 892194.850632161)]'] connector: <aiohttp.connector.TCPConnector object at 0xf5bc60c0> Task was destroyed but it is pending! task: <Task pending name='Task-15' coro=<AsyncioPahoClient._loop_misc() running at /home/admin/.local/lib/python3.12/site-packages/asyncio_paho/client.py:363> wait_for=> Exception ignored in: <function Client.del at 0xf5c680c8> Traceback (most recent call last): File "/home/admin/.local/lib/python3.12/site-packages/paho/mqtt/client.py", line 636, in del File "/home/admin/.local/lib/python3.12/site-packages/paho/mqtt/client.py", line 675, in _reset_sockets File "/home/admin/.local/lib/python3.12/site-packages/paho/mqtt/client.py", line 668, in _sock_close File "/home/admin/.local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2200, in _call_socket_close File "/home/admin/.local/lib/python3.12/site-packages/myskoda/mqtt.py", line 179, in _on_socket_close File "/home/admin/.local/lib/python3.12/site-packages/myskoda/mqtt.py", line 148, in reconnect File "/usr/local/lib/python3.12/asyncio/tasks.py", line 417, in create_task RuntimeError: no running event loop sys:1: RuntimeWarning: coroutine 'Mqtt.connect' was never awaited

scoutice commented 1 month ago

i propose to add the missing field by reading from the aircondition. eg.

myVehicle: Vehicle = await myskoda.get_vehicle(VIN)
if myVehicle.charging.status.state == ChargingState.INVALID and myVehicle.air_conditioning.charger_connection_state == ConnectionState.CONNECTED:
    print("OVERRIDE myVehicle.charging.status.state with '" + ChargingState.READY_FOR_CHARGING + "'") 
    myVehicle.charging.status.state = ChargingState.READY_FOR_CHARGING

and extending the class ChargingState and setting ChargingState as optional with an invalid default value

class ChargingStatus(DataClassORJSONMixin):
    battery: Battery
    charging_rate_in_kilometers_per_hour: float = field(
        metadata=field_options(alias="chargingRateInKilometersPerHour")
    )
    charge_power_in_kw: float | None = field(
        default=None, metadata=field_options(alias="chargePowerInKw")
    )
    --> state: ChargingState | None = field(default=ChargingState.INVALID, metadata=field_options(alias="chargeState")) <--
    charge_type: ChargeType | None = field(default=None, metadata=field_options(alias="chargeType"))
    remaining_time_to_fully_charged_in_minutes: int | None = field(
        default=None, metadata=field_options(alias="remainingTimeToFullyChargedInMinutes")
    )

class ChargingState(StrEnum):
    READY_FOR_CHARGING = "READY_FOR_CHARGING"
    CONNECT_CABLE = "CONNECT_CABLE"
    CONSERVING = "CONSERVING"
    CHARGING = "CHARGING"
    --> INVALID = "INVALID" <--
WebSpider commented 1 month ago

Can you please check with the most recent version of the library? Thanks!

scoutice commented 1 month ago

Still the same (Commit# (latest one) 8582861e18f921cbab504c26e3b2a4542364ff1a)

pydev debugger: starting (pid: 17484) DEBUG:asyncio:Using selector: SelectSelector INFO:myskoda.myskoda:IDK Authorization was successful. DEBUG:myskoda.mqtt:Connecting to MQTT on mqtt.messagehub.de:8883... DEBUG:myskoda.mqtt:Using user id 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd... INFO:myskoda.mqtt:MQTT Connected. DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/set-air-conditioning-at-unlock DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/set-air-conditioning-seats-heating DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/set-air-conditioning-timers DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/set-air-conditioning-without-external-power DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/set-target-temperature DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/start-stop-air-conditioning DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/start-stop-auxiliary-heating DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/start-stop-window-heating DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/air-conditioning/windows-heating DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/start-stop-charging DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-battery-support DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-auto-unlock-plug DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-care-mode DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-charge-limit DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-charge-mode DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-charging-profiles DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/charging/update-charging-current DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/vehicle-access/honk-and-flash DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/vehicle-access/lock-vehicle DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/vehicle-services-backup/apply-backup DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/operation-request/vehicle-wakeup/wakeup DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/service-event/air-conditioning DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/service-event/charging DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/service-event/vehicle-status/access DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/service-event/vehicle-status/lights DEBUG:myskoda.mqtt:Subscribing to topic: 6f5bdac1-40b0-48a8-9d9e-05c8a7b0d1cd/MYVINMYVINMYVINMYVIN/account-event/account-event/privacy DEBUG:myskoda.myskoda:Myskoda ready. ERROR:myskoda.rest_api:Failed to load data from url /v1/charging/MYVINMYVINMYVINMYVIN. Return value was '{"isVehicleInSavedLocation":false,"status":{"chargingRateInKilometersPerHour":0.0,"chargePowerInKw":0.0,"remainingTimeToFullyChargedInMinutes":0,"battery":{"remainingCruisingRangeInMeters":263000,"stateOfChargeInPercent":64}},"settings":{"targetStateOfChargeInPercent":80,"preferredChargeMode":"MANUAL","availableChargeModes":["MANUAL"],"chargingCareMode":"DEACTIVATED","autoUnlockPlugWhenCharged":"OFF","maxChargeCurrentAc":"MAXIMUM","batterySupport":"DISABLED"},"carCapturedTimestamp":"2024-10-03T13:12:36Z","errors":[{"type":"STATUS_OF_CHARGING_NOT_AVAILABLE","description":"Status of charging is not available."}]}' Traceback (most recent call last): File "", line 24, in mashumaro_from_json File "", line 14, in __mashumaro_from_dict_json__ mashumaro.exceptions.MissingField: Field "state" of type ChargingState is missing in ChargingStatus instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\Entwicklung\Workspace\Github\skodaconnect_myskoda\myskoda\rest_api.py", line 41, in _make_get_request data = deserialize(response_text) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 26, in mashumaro_from_json mashumaro.exceptions.InvalidFieldValue: Field "status" of type Optional[ChargingStatus] in Charging has invalid value {'chargingRateInKilometersPerHour': 0.0, 'chargePowerInKw': 0.0, 'remainingTimeToFullyChargedInMinutes': 0, 'battery': {'remainingCruisingRangeInMeters': 263000, 'stateOfChargeInPercent': 64}} Traceback (most recent call last): File "", line 24, in mashumaro_from_json File "", line 14, in __mashumaro_from_dict_json__ mashumaro.exceptions.MissingField: Field "state" of type ChargingState is missing in ChargingStatus instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc\pydevd.py", line 3616, in main() File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc\pydevd.py", line 3609, in main globals = debugger.run(setup['file'], None, None, is_module) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc\pydevd.py", line 2626, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc\pydevd.py", line 2634, in _exec globals = pydevd_runpy.run_path(file, globals, 'main') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc_pydevd_bundle\pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:\Users\User.p2\pool\plugins\org.python.pydev.core_12.0.0.202402010911\pysrc_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "D:\Entwicklung\Workspace\WallboxController_Python\src_myskoda\myskoda_get_all_info.py", line 127, in asyncio.run(main()) ^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python312\Lib\asyncio\runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Program Files\Python312\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "D:\Entwicklung\Workspace\WallboxController_Python\src_myskoda\myskoda_get_all_info.py", line 27, in main charging: Charging = await myskoda.get_charging(VIN) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Entwicklung\Workspace\Github\skodaconnect_myskoda\myskoda\myskoda.py", line 163, in get_charging return await self.rest_api.get_charging(vin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Entwicklung\Workspace\Github\skodaconnect_myskoda\myskoda\rest_api.py", line 59, in get_charging return await self._make_get_request(f"/v1/charging/{vin}", Charging.from_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Entwicklung\Workspace\Github\skodaconnect_myskoda\myskoda\rest_api.py", line 41, in _make_get_request data = deserialize(response_text) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 26, in mashumaro_from_json mashumaro.exceptions.InvalidFieldValue: Field "status" of type Optional[ChargingStatus] in Charging has invalid value {'chargingRateInKilometersPerHour': 0.0, 'chargePowerInKw': 0.0, 'remainingTimeToFullyChargedInMinutes': 0, 'battery': {'remainingCruisingRangeInMeters': 263000, 'stateOfChargeInPercent': 64}}

WebSpider commented 1 month ago

Fixed in https://github.com/skodaconnect/myskoda/pull/84