diff --git a/custom_components/drivvo/config_flow.py b/custom_components/drivvo/config_flow.py index 6602991..44d0ed7 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,