Address review comments and minor fix for Mazda integration (#47702)

* Address comments from code review

* Fix handling of missing sensor values

* Use default timeout for get_vehicles

* Fix test_update_auth_failure
This commit is contained in:
Brandon Rothweiler 2021-03-15 01:57:39 -04:00 committed by GitHub
parent bcadccf7aa
commit fbf3225234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 46 deletions

View file

@ -91,7 +91,13 @@ class MazdaFuelDistanceSensor(MazdaEntity):
fuel_distance_km = self.coordinator.data[self.index]["status"][
"fuelDistanceRemainingKm"
]
return round(self.hass.config.units.length(fuel_distance_km, LENGTH_KILOMETERS))
return (
None
if fuel_distance_km is None
else round(
self.hass.config.units.length(fuel_distance_km, LENGTH_KILOMETERS)
)
)
class MazdaOdometerSensor(MazdaEntity):
@ -124,7 +130,11 @@ class MazdaOdometerSensor(MazdaEntity):
def state(self):
"""Return the state of the sensor."""
odometer_km = self.coordinator.data[self.index]["status"]["odometerKm"]
return round(self.hass.config.units.length(odometer_km, LENGTH_KILOMETERS))
return (
None
if odometer_km is None
else round(self.hass.config.units.length(odometer_km, LENGTH_KILOMETERS))
)
class MazdaFrontLeftTirePressureSensor(MazdaEntity):
@ -154,11 +164,10 @@ class MazdaFrontLeftTirePressureSensor(MazdaEntity):
@property
def state(self):
"""Return the state of the sensor."""
return round(
self.coordinator.data[self.index]["status"]["tirePressure"][
"frontLeftTirePressurePsi"
]
)
tire_pressure = self.coordinator.data[self.index]["status"]["tirePressure"][
"frontLeftTirePressurePsi"
]
return None if tire_pressure is None else round(tire_pressure)
class MazdaFrontRightTirePressureSensor(MazdaEntity):
@ -188,11 +197,10 @@ class MazdaFrontRightTirePressureSensor(MazdaEntity):
@property
def state(self):
"""Return the state of the sensor."""
return round(
self.coordinator.data[self.index]["status"]["tirePressure"][
"frontRightTirePressurePsi"
]
)
tire_pressure = self.coordinator.data[self.index]["status"]["tirePressure"][
"frontRightTirePressurePsi"
]
return None if tire_pressure is None else round(tire_pressure)
class MazdaRearLeftTirePressureSensor(MazdaEntity):
@ -222,11 +230,10 @@ class MazdaRearLeftTirePressureSensor(MazdaEntity):
@property
def state(self):
"""Return the state of the sensor."""
return round(
self.coordinator.data[self.index]["status"]["tirePressure"][
"rearLeftTirePressurePsi"
]
)
tire_pressure = self.coordinator.data[self.index]["status"]["tirePressure"][
"rearLeftTirePressurePsi"
]
return None if tire_pressure is None else round(tire_pressure)
class MazdaRearRightTirePressureSensor(MazdaEntity):
@ -256,8 +263,7 @@ class MazdaRearRightTirePressureSensor(MazdaEntity):
@property
def state(self):
"""Return the state of the sensor."""
return round(
self.coordinator.data[self.index]["status"]["tirePressure"][
"rearRightTirePressurePsi"
]
)
tire_pressure = self.coordinator.data[self.index]["status"]["tirePressure"][
"rearRightTirePressurePsi"
]
return None if tire_pressure is None else round(tire_pressure)