Skip to content

Commit

Permalink
fix: code formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 committed Sep 20, 2022
1 parent 8ef3dd3 commit fb91f4b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
27 changes: 20 additions & 7 deletions src/kegtron_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from bluetooth_data_tools import short_address
from bluetooth_sensor_state_data import BluetoothData
from home_assistant_bluetooth import BluetoothServiceInfo
from sensor_state_data import SensorLibrary, Units
from sensor_state_data import SensorLibrary

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -75,13 +75,20 @@ def _start_update(self, service_info: BluetoothServiceInfo) -> None:
else:
return

self.set_title(f"{self.manufacturer} {self.model} {short_address(self.address)}")
self.set_device_name(f"{self.manufacturer} {self.model} {short_address(self.address)}")
self.set_title(
f"{self.manufacturer} {self.model} {short_address(self.address)}"
)
self.set_device_name(
f"{self.manufacturer} {self.model} {short_address(self.address)}"
)
self.set_device_type(self.model)
self.set_device_manufacturer(self.manufacturer)

if self.model == "KT-200":
self.set_device_name(f"{self.manufacturer} {self.model} {short_address(self.address)}", self.device_id)
self.set_device_name(
f"{self.manufacturer} {self.model} {short_address(self.address)}",
self.device_id
)
self.set_device_type(self.model, self.device_id)
self.set_device_manufacturer(self.manufacturer, self.device_id)

Expand Down Expand Up @@ -115,21 +122,27 @@ def _process_update(self, data: bytes) -> None:
)
self.update_sensor(
key=f"keg_size{self.port_id}",
native_unit_of_measurement=SensorLibrary.KEG_SIZE__VOLUME_LITERS.native_unit_of_measurement,
native_unit_of_measurement=(
SensorLibrary.KEG_SIZE__VOLUME_LITERS.native_unit_of_measurement
),
native_value=keg_size / 1000,
device_class=SensorLibrary.KEG_SIZE__VOLUME_LITERS.device_class,
device_id=self.device_id,
)
self.update_sensor(
key=f"keg_type{self.port_id}",
native_unit_of_measurement=SensorLibrary.KEG_TYPE__NONE.native_unit_of_measurement,
native_unit_of_measurement=(
SensorLibrary.KEG_TYPE__NONE.native_unit_of_measurement
),
native_value=keg_type,
device_class=SensorLibrary.KEG_TYPE__NONE.device_class,
device_id=self.device_id,
)
self.update_sensor(
key=f"volume_start{self.port_id}",
native_unit_of_measurement=SensorLibrary.VOLUME_START__VOLUME_LITERS.native_unit_of_measurement,
native_unit_of_measurement=(
SensorLibrary.VOLUME_START__VOLUME_LITERS.native_unit_of_measurement)
,
native_value=vol_start / 1000,
device_class=SensorLibrary.VOLUME_START__VOLUME_LITERS.device_class,
device_id=self.device_id,
Expand Down
65 changes: 42 additions & 23 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,47 +160,61 @@ def test_kegtron_kt200():
sw_version=None,
hw_version=None,
),
'port 2': SensorDeviceInfo(
name='Kegtron KT-200 9B75',
model='KT-200',
manufacturer='Kegtron',
"port 2": SensorDeviceInfo(
name="Kegtron KT-200 9B75",
model="KT-200",
manufacturer="Kegtron",
sw_version=None,
hw_version=None
)
hw_version=None,
),
},
entity_descriptions={
DeviceKey(key=KEY_PORT_COUNT, device_id=None): SensorDescription(
device_key=DeviceKey(key=KEY_PORT_COUNT, device_id=None),
device_class=SensorDeviceClass.PORT_COUNT,
native_unit_of_measurement=None,
),
DeviceKey(key=f"{KEY_KEG_SIZE}_port_2", device_id="port 2"): SensorDescription(
DeviceKey(
key=f"{KEY_KEG_SIZE}_port_2", device_id="port 2"
): SensorDescription(
device_key=DeviceKey(key=f"{KEY_KEG_SIZE}_port_2", device_id="port 2"),
device_class=SensorDeviceClass.KEG_SIZE,
native_unit_of_measurement=Units.VOLUME_LITERS,
),
DeviceKey(key=f"{KEY_KEG_TYPE}_port_2", device_id="port 2"): SensorDescription(
DeviceKey(
key=f"{KEY_KEG_TYPE}_port_2", device_id="port 2"
): SensorDescription(
device_key=DeviceKey(key=f"{KEY_KEG_TYPE}_port_2", device_id="port 2"),
device_class=SensorDeviceClass.KEG_TYPE,
native_unit_of_measurement=None,
),
DeviceKey(key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"): SensorDescription(
DeviceKey(
key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"
): SensorDescription(
device_key=DeviceKey(key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"),
device_class=SensorDeviceClass.VOLUME_START,
native_unit_of_measurement=Units.VOLUME_LITERS,
),
DeviceKey(key=f"{KEY_PORT_STATE}_port_2", device_id="port 2"): SensorDescription(
DeviceKey(
key=f"{KEY_PORT_STATE}_port_2", device_id="port 2"
): SensorDescription(
device_key=DeviceKey(key=f"{KEY_PORT_STATE}_port_2", device_id="port 2"),
device_class=SensorDeviceClass.PORT_STATE,
native_unit_of_measurement=None,
),
DeviceKey(key=f"{KEY_PORT_NAME}_port_2", device_id="port 2"): SensorDescription(
DeviceKey(
key=f"{KEY_PORT_NAME}_port_2", device_id="port 2"
): SensorDescription(
device_key=DeviceKey(key=f"{KEY_PORT_NAME}_port_2", device_id="port 2"),
device_class=SensorDeviceClass.PORT_NAME,
native_unit_of_measurement=None,
),
DeviceKey(key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"): SensorDescription(
device_key=DeviceKey(key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"),
DeviceKey(
key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"
): SensorDescription(
device_key=DeviceKey(
key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"
),
device_class=SensorDeviceClass.VOLUME_DISPENSED,
native_unit_of_measurement=Units.VOLUME_LITERS,
),
Expand All @@ -214,11 +228,6 @@ def test_kegtron_kt200():
device_class=DeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
),
DeviceKey(key=KEY_SIGNAL_STRENGTH, device_id=None): SensorDescription(
device_key=DeviceKey(key=KEY_SIGNAL_STRENGTH, device_id=None),
device_class=DeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
),
},
entity_values={
DeviceKey(key=KEY_PORT_COUNT, device_id=None): SensorValue(
Expand All @@ -236,13 +245,19 @@ def test_kegtron_kt200():
name="Keg Type Port 2",
native_value="Other (58.93 L)",
),
DeviceKey(key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"): SensorValue(
device_key=DeviceKey(key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"),
DeviceKey(
key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"
): SensorValue(
device_key=DeviceKey(
key=f"{KEY_VOLUME_START}_port_2", device_id="port 2"
),
name="Volume Start Port 2",
native_value=15.0,
),
DeviceKey(key=f"{KEY_PORT_STATE}_port_2", device_id="port 2"): SensorValue(
device_key=DeviceKey(key=f"{KEY_PORT_STATE}_port_2", device_id="port 2"),
device_key=DeviceKey(
key=f"{KEY_PORT_STATE}_port_2", device_id="port 2"
),
name="Port State Port 2",
native_value="Configured",
),
Expand All @@ -251,8 +266,12 @@ def test_kegtron_kt200():
name="Port Name Port 2",
native_value="2nd Port",
),
DeviceKey(key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"): SensorValue(
device_key=DeviceKey(key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"),
DeviceKey(
key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"
): SensorValue(
device_key=DeviceKey(
key=f"{KEY_VOLUME_DISPENSED}_port_2", device_id="port 2"
),
name="Volume Dispensed Port 2",
native_value=0.738,
),
Expand Down

0 comments on commit fb91f4b

Please sign in to comment.