diff --git a/src/const.py b/src/const.py index f849311..5f944f4 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.9.1" +VERSION = "v1.9.2" OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2" diff --git a/src/mqtt.py b/src/mqtt.py index 043a657..4c2ae89 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -47,25 +47,37 @@ def connect(): def create_otp_input(): + state_topic = otp_mqtt_topic + "/state" config = { "name": "Volvo OTP", "object_id": f"volvo_otp", "schema": "state", "command_topic": otp_mqtt_topic, - "unique_id": f"volvoAAOS2mqtt_otp", - "pattern": "\d{6}", - "icon": "mdi:two-factor-authentication" + "state_topic": state_topic, + "unique_id": "volvoAAOS2mqtt_otp", + "pattern": r"\d{6}", + "icon": "mdi:two-factor-authentication", + "mode": "text" } mqtt_client.publish( - f"homeassistant/text/volvoAAOS2mqtt/volvo_otp/config", + "homeassistant/text/volvoAAOS2mqtt/volvo_otp/config", json.dumps(config), retain=True ) -def delete_otp_input(): - topic = "homeassistant/text/volvoAAOS2mqtt/volvo_otp/config" - mqtt_client.publish(topic, payload="", retain=True) + mqtt_client.publish( + state_topic, + "000000", + retain=True + ) + +def set_otp_state(): + mqtt_client.publish( + otp_mqtt_topic + "/state", + otp_code, + retain=True + ) def send_car_images(vin, data, device): diff --git a/src/volvo.py b/src/volvo.py index 531b223..0d21dd8 100644 --- a/src/volvo.py +++ b/src/volvo.py @@ -156,7 +156,7 @@ def send_otp(auth_session, data): if not mqtt.otp_code: raise Exception ("No OTP found, exting...") - mqtt.delete_otp_input() + mqtt.set_otp_state() auth = auth_session.post(next_url, data=json.dumps(body)) if auth.status_code == 200: return auth.json()