Skip to content

Commit

Permalink
Update Ruff version and use ruff-format instead of black formatter (#199
Browse files Browse the repository at this point in the history
)
  • Loading branch information
koenvervloesem authored Dec 23, 2023
1 parent 8479bfb commit fda7431
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
---
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.285'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.9'
hooks:
- id: ruff-format
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.8.0
hooks:
- id: mypy
entry: env MYPYPATH=TheengsGateway mypy
Expand Down
4 changes: 1 addition & 3 deletions TheengsGateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def main() -> None:
# Remove /sensor if existing in the configuration as we now handle different types
# of devices.
if configuration["discovery_topic"].endswith("/sensor"):
configuration["discovery_topic"] = configuration["discovery_topic"][
:-7
]
configuration["discovery_topic"] = configuration["discovery_topic"][:-7]

if not configuration["host"]:
sys.exit("MQTT host is not specified")
Expand Down
6 changes: 2 additions & 4 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ def hass_presence(self, decoded_json) -> None: # noqa: ANN001
return
txpower = decoded_json.get("txpower", 0)
if txpower >= 0:
txpower = (
-59
) # if tx power is not found we set a default calibration value
txpower = -59 # if tx power is not found we set a default calibration value
logger.debug("rssi: %d, txpower: %d", rssi, txpower)
ratio = rssi / txpower
if ratio < 1.0: # noqa: PLR2004
Expand Down Expand Up @@ -356,7 +354,7 @@ async def ble_scan_loop(self) -> None:
if self.configuration["adapter"]:
scanner_kwargs["adapter"] = self.configuration["adapter"]

scanner_kwargs["detection_callback"] = self.detection_callback # type: ignore[assignment] # noqa: E501
scanner_kwargs["detection_callback"] = self.detection_callback # type: ignore[assignment]
scanner = BleakScanner(**scanner_kwargs) # type: ignore[arg-type]
logger.info("Starting BLE scan")
while not self.stopped:
Expand Down
10 changes: 3 additions & 7 deletions TheengsGateway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def parse_args() -> argparse.Namespace:
"-Dh",
"--hass_discovery",
type=int,
help="Enable(1) or disable(0) Home Assistant MQTT discovery "
"(default: 1)",
help="Enable(1) or disable(0) Home Assistant MQTT discovery (default: 1)",
)
parser.add_argument(
"-Dn",
Expand Down Expand Up @@ -208,8 +207,7 @@ def parse_args() -> argparse.Namespace:
"-tf",
"--time_format",
type=int,
help="Use 12-hour (1) or 24-hour (0) time format for clocks "
"(default: 0)",
help="Use 12-hour (1) or 24-hour (0) time format for clocks (default: 0)",
)
parser.add_argument(
"-tls",
Expand Down Expand Up @@ -282,9 +280,7 @@ def merge_args_with_config(config: dict, args: argparse.Namespace) -> None:
)
else:
config[key].extend(
element
for element in value
if element not in config[key]
element for element in value if element not in config[key]
)
elif key != "config":
config[key] = value
8 changes: 2 additions & 6 deletions TheengsGateway/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ def publish_device_info(self, pub_device) -> None: # noqa: ANN001
if pub_device["properties"][k]["name"] in ha_dev_classes:
device["dev_cla"] = pub_device["properties"][k]["name"]
if pub_device["properties"][k]["unit"] in ha_dev_units:
device["unit_of_meas"] = pub_device["properties"][k][
"unit"
]
device["unit_of_meas"] = pub_device["properties"][k]["unit"]
device["state_class"] = "measurement"
entity_type = "sensor"
elif pub_device["properties"][k]["unit"] == "status":
Expand Down Expand Up @@ -209,9 +207,7 @@ def prepare_hadevice(self, uuid: str, device: dict) -> dict:
def build_state_topic(self, device: dict) -> str:
"""Build state topic."""
state_topic = (
self.configuration["publish_topic"]
+ "/"
+ device["id"].replace(":", "")
self.configuration["publish_topic"] + "/" + device["id"].replace(":", "")
)
return re.sub(
r".+?/",
Expand Down

0 comments on commit fda7431

Please sign in to comment.