Enable BMW component to be unit system aware (#17197)
* Enable BMW component to be unit system aware * lint fixes * use constants for config entries * remove configuration from component and rely only on HA config of unit_system * remove unused import * update code to reflect feedback * lint fixes * remove unnecessary comments * rework return statement to satisfy pylint * more lint fixes * add tests for volume utils * lint fixes * more lint fixes * remove unnecessary comments
This commit is contained in:
1 parent
58af332d21
commit
cffb704311
6 files changed
+158
-20
No files matched your search
@@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||
TEMPERATURE, UNIT_NOT_RECOGNIZED_TEMPLATE)
|
||||
from homeassistant.util import temperature as temperature_util
|
||||
from homeassistant.util import distance as distance_util
|
||||
from homeassistant.util import volume as volume_util
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -108,6 +109,13 @@ class UnitSystem:
|
||||
return distance_util.convert(length, from_unit,
|
||||
self.length_unit)
|
||||
|
||||
def volume(self, volume: Optional[float], from_unit: str) -> float:
|
||||
"""Convert the given volume to this unit system."""
|
||||
if not isinstance(volume, Number):
|
||||
raise TypeError('{} is not a numeric value.'.format(str(volume)))
|
||||
|
||||
return volume_util.convert(volume, from_unit, self.volume_unit)
|
||||
|
||||
def as_dict(self) -> dict:
|
||||
"""Convert the unit system to a dictionary."""
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user