From 2d1a0984247138583ee0feda72456c5930f9d0ed Mon Sep 17 00:00:00 2001 From: dougiteixeira <31328123+dougiteixeira@users.noreply.github.com> Date: Mon, 24 Apr 2023 06:17:19 -0300 Subject: [PATCH] fix --- custom_components/drivvo/config_flow.py | 24 ++++++++++++++++++------ custom_components/drivvo/sensor.py | 9 ++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/custom_components/drivvo/config_flow.py b/custom_components/drivvo/config_flow.py index 38a8f03..f6af909 100644 --- a/custom_components/drivvo/config_flow.py +++ b/custom_components/drivvo/config_flow.py @@ -90,9 +90,15 @@ async def async_step_init(self, user_input: dict[str, Any]) -> FlowResult: resource_vehicle = {} for vehicle in vehicles: if vehicle["ativo"]: - resource_vehicle[ - str(vehicle["id_veiculo"]) - ] = f"{vehicle['nome']} - {vehicle['placa']} {vehicle['marca']}/{vehicle['modelo']} ({vehicle['id_veiculo']})" + vehicle_name = "" + if vehicle["nome"] is not None and vehicle["nome"] != "": + vehicle_name += f"{vehicle['nome']} - " + if vehicle["placa"] is not None and vehicle["placa"] != "": + vehicle_name += f"{vehicle['placa']} - " + vehicle_name += ( + f"{vehicle['marca']}/{vehicle['modelo']} ({vehicle['id_veiculo']})" + ) + resource_vehicle[str(vehicle["id_veiculo"])] = vehicle_name old_vehicles = [] @@ -221,9 +227,15 @@ async def async_step_vehicle( _LOGGER.debug("Veiculos: %s", vehicles) for vehicle in vehicles: if vehicle["ativo"]: - resource_vehicle[ - str(vehicle["id_veiculo"]) - ] = f"{vehicle['nome']} - {vehicle['placa']} {vehicle['marca']}/{vehicle['modelo']} ({vehicle['id_veiculo']})" + vehicle_name = "" + if vehicle["nome"] is not None and vehicle["nome"] != "": + vehicle_name += f"{vehicle['nome']} - " + if vehicle["placa"] is not None and vehicle["placa"] != "": + vehicle_name += f"{vehicle['placa']} - " + vehicle_name += ( + f"{vehicle['marca']}/{vehicle['modelo']} ({vehicle['id_veiculo']})" + ) + resource_vehicle[str(vehicle["id_veiculo"])] = vehicle_name if len(resource_vehicle) == 0: return self.async_create_entry( diff --git a/custom_components/drivvo/sensor.py b/custom_components/drivvo/sensor.py index 267e3fc..9b015c8 100755 --- a/custom_components/drivvo/sensor.py +++ b/custom_components/drivvo/sensor.py @@ -53,12 +53,19 @@ async def async_setup_entry( info="base", ) ) is not None: + if vehicle_data["nome"] is not None and vehicle_data["nome"] != "": + vehicle_name = vehicle_data["nome"] + elif vehicle_data["placa"] is not None and vehicle_data["placa"] != "": + vehicle_name = vehicle_data["placa"] + else: + vehicle_name = f"{vehicle_data['marca']}/{vehicle_data['modelo']}" + async_add_entities( [ DrivvoSensor( hass, config[CONF_EMAIL], - vehicle_data["nome"], + vehicle_name, vehicle_data["marca"], vehicle_data["modelo"], vehicle,