Skip to content

Commit

Permalink
[CI] Enable all Ruff rules (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvervloesem committed Aug 11, 2023
1 parent 166d777 commit f2964ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
28 changes: 17 additions & 11 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def on_connect(
client.publish(
self.configuration["lwt_topic"],
"online",
0,
True,
qos=0,
retain=True,
)
self.subscribe(self.configuration["subscribe_topic"])
else:
Expand Down Expand Up @@ -166,8 +166,8 @@ def on_disconnect(
self.client.will_set(
self.configuration["lwt_topic"],
"offline",
0,
True,
qos=0,
retain=True,
)
self.client.on_connect = on_connect
self.client.on_disconnect = on_disconnect
Expand All @@ -184,8 +184,8 @@ def disconnect_mqtt(self) -> None:
self.client.publish(
self.configuration["lwt_topic"],
"offline",
0,
True,
qos=0,
retain=True,
)
self.client.disconnect()

Expand Down Expand Up @@ -234,7 +234,7 @@ def hass_presence(self, decoded_json) -> None: # noqa: ANN001
) # 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:
if ratio < 1.0: # noqa: PLR2004
distance = pow(ratio, 10)
else:
distance = 0.89976 * pow(ratio, 7.7095) + 0.111
Expand All @@ -244,7 +244,7 @@ def publish(
self,
msg, # noqa: ANN001
pub_topic=None, # noqa: ANN001
retain=False, # noqa: ANN001
retain=False, # noqa: ANN001,FBT002
) -> None:
"""Publish <msg> to MQTT topic <pub_topic>."""
if not pub_topic:
Expand Down Expand Up @@ -273,7 +273,9 @@ def add_clock(self, address: str) -> None:
logger.info(
"Found device %s, synchronizing time daily beginning from %s",
address,
datetime.fromtimestamp(start_time + SECONDS_IN_DAY).strftime(
datetime.fromtimestamp( # noqa: DTZ006
start_time + SECONDS_IN_DAY,
).strftime(
"%Y-%m-%d %H:%M:%S",
),
)
Expand Down Expand Up @@ -325,7 +327,7 @@ async def update_clock_times(self) -> None:
logger.info(
"Synchronizing time with %s again on %s",
address,
datetime.fromtimestamp(
datetime.fromtimestamp( # noqa: DTZ006
this_time + SECONDS_IN_DAY,
).strftime("%Y-%m-%d %H:%M:%S"),
)
Expand Down Expand Up @@ -472,7 +474,11 @@ def decode_advertisement(
add_manufacturer(data_json, company_id)
self.publish_json(data_json, decoded=False)

def publish_json(self, data_json: DataJSONType, decoded: bool) -> None:
def publish_json(
self,
data_json: DataJSONType,
decoded: bool, # noqa: FBT001
) -> None:
"""Publish JSON data to MQTT."""
message = json.dumps(data_json)
self.publish(
Expand Down
2 changes: 1 addition & 1 deletion TheengsGateway/decryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def replace_encrypted_data(
"""Replace the encrypted data by decrypted payload."""


class LYWSD03MMC_PVVXDecryptor(AdvertisementDecryptor):
class LYWSD03MMC_PVVXDecryptor(AdvertisementDecryptor): # noqa: N801
"""Class for decryption of LYWSD03MMX PVVX encrypted advertisements."""

def compute_nonce(self, address: str, decoded_json: Dict) -> bytes:
Expand Down
2 changes: 1 addition & 1 deletion TheengsGateway/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def publish_device_info(self, pub_device) -> None: # noqa: ANN001
device["state_class"] = "measurement"
config_topic = discovery_topic + "-" + k + "/config"
device["device"] = hadevice
self.publish(json.dumps(device), config_topic, True)
self.publish(json.dumps(device), config_topic, retain=True)

self.discovered_entities.append(pub_device_uuid)
self.publish(
Expand Down
23 changes: 3 additions & 20 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
select = [
"ANN", # flake8-annotations
"ARG", # flake8-unused-arguments
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"COM", # flake8-commas
"D", # pydocstyle
"E", # pycodestyle
"EM", # flake8-errmsg
"F", # Pyflakes
"G", # flake8-logging-format
"I", # isort
"PTH", # flake8-use-pathlib
"PIE", # flake8-pie
"RET", # flake8-return
"RSE", # flake8-raise
"S", # flake8-bandit
"SIM", # flake8-simplify
"TRY", # Tryceratops
]
select = ["ALL"]
ignore = [
"ANN101", # missing-type-self
"D107", # undocumented-public-init
"N999", # invalid-module-name
"T201", # print
]
# Always generate Python 3.8-compatible code
target-version = "py38"
Expand Down

0 comments on commit f2964ca

Please sign in to comment.