Skip to content

Commit

Permalink
Megalinter now passes
Browse files Browse the repository at this point in the history
  • Loading branch information
ha-enthus1ast committed Dec 7, 2023
1 parent 0892420 commit b4db06f
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 144 deletions.
12 changes: 4 additions & 8 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ PYTHON_PYLINT_PRE_COMMANDS:
- command: pip install pylint-pydantic
venv: pylint
continue_if_failed: false
# If you use ENABLE variable, all other languages/formats/tooling-formats will
# be disabled by default
# ENABLE:

PYTHON_PYLINT_ARGUMENTS:
# Disable import checks because it needs all the Python dependencies installed in the linter
Expand All @@ -23,17 +20,16 @@ PYTHON_PYLINT_ARGUMENTS:
- "--load-plugins=pylint_pydantic"
PYTHON_FLAKE8_ARGUMENTS:
- "--max-line-length=100"
# If you use ENABLE_LINTERS variable, all other linters will be disabled by
# default
# ENABLE_LINTERS:

DISABLE_LINTERS:
- SPELL_CSPELL
- PYTHON_PYRIGHT # TODO this should not be disabled!!
- PYTHON_MYPY # TODO this should not be disabled!!
- REPOSITORY_CHECKOV # TODO this should not be disabled!!
- COPYPASTE_JSCPD # TODO this should not be disabled!!

SHOW_ELAPSED_TIME: true

FILEIO_REPORTER: false
# Uncomment if you want MegaLinter to detect errors but not block CI to pass
# DISABLE_ERRORS: true

PYTHON_BANDIT_FILTER_REGEX_EXCLUDE: test_
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM python:3

RUN apt-get update && apt-get --no-install-recommends install -y bluez bluetooth sudo
RUN apt-get update && apt-get --no-install-recommends install -y bluez=5.66 bluetooth=5.50-1.2 && rm -rf /var/lib/apt/lists/*

RUN adduser --disabled-password --gecos '' myuser

# Copy and install application
WORKDIR /usr/src/app
COPY setup.py ./
COPY plejd ./plejd
RUN pip3 install .
RUN pip3 install --no-cache-dir .

# Docker entrypoint
COPY docker-entrypoint.sh .
Expand All @@ -17,4 +17,9 @@ RUN chmod +x ./docker-entrypoint.sh
# Switch to the new user
USER myuser

# Healthcheck
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost/ || exit 1


ENTRYPOINT ["./docker-entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sudo service bluetooth start
# We must wait for bluetooth service to start
msg="Waiting for services to start..."
time=0
echo -n $msg
echo -n "$msg"
while [[ "$(pidof start-stop-daemon)" != "" ]]; do
sleep 1
time=$((time + 1))
Expand Down
6 changes: 0 additions & 6 deletions ha_plejd_mqtt/bt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ async def send_command(
response_type: Type of response
"""
if not self.is_connected():
print("Not connected")
error_message = "Trying to send command when not connected to Plejd mesh"
logging.error(error_message)
raise PlejdNotConnectedError(error_message)
Expand Down Expand Up @@ -263,8 +262,6 @@ async def ping(self) -> bool:
except (PlejdBluetoothError, PlejdNotConnectedError, PlejdTimeoutError) as err:
logging.info(f"Ping operation failed: {str(err)}")
return False
print("pong_data",pong_data)
print("ping_data",ping_data)

if pong_data == bytearray() or not ((ping_data[0] + 1) & 0xFF) == pong_data[0]:
return False
Expand Down Expand Up @@ -369,18 +366,15 @@ async def set_plejd_time(self, plejd_device: BTDeviceInfo, time: datetime) -> bo
"""
timestamp = struct.pack("<I", int(time.timestamp())) + b"\x00"
try:
print(self.is_connected())
await self.send_command(
plejd_device.ble_address,
constants.PlejdCommand.BLE_CMD_TIME_UPDATE.value,
timestamp.hex(),
constants.PlejdResponse.BLE_REQUEST_NO_RESPONSE.value,
)
print("No error")
except (PlejdBluetoothError, PlejdNotConnectedError, PlejdTimeoutError) as err:
error_message = f"Failed to set time in Plejd mesh: {str(err)}"
logging.error(error_message)
print("ERROR")
raise

logging.debug("Successfully set plejd time to: %s", time)
Expand Down
25 changes: 18 additions & 7 deletions ha_plejd_mqtt/mdl/bt_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
from typing import Callable, Generic, TypeVar

from ha_plejd_mqtt import constants
from ha_plejd_mqtt.bt_client import BTClient, PlejdBluetoothError, PlejdNotConnectedError, PlejdTimeoutError
from ha_plejd_mqtt.bt_client import (
BTClient,
PlejdBluetoothError,
PlejdNotConnectedError,
PlejdTimeoutError,
)
from ha_plejd_mqtt.mdl.bt_data_type import BTData, BTLightData
from ha_plejd_mqtt.mdl.bt_device_info import BTDeviceInfo, BTLightInfo

Expand Down Expand Up @@ -83,12 +88,14 @@ async def on(self) -> bool:
)
except PlejdNotConnectedError as err:
logging.warning(
f"Device {self._device_info.name} is not connected, cannot turn on. Error: {str(err)}"
f"Device {self._device_info.name} is not connected, cannot turn on."
f"Error: {str(err)}"
)
return False
except (PlejdBluetoothError, PlejdTimeoutError) as err:
logging.warning(
f"Failed to turn on device {self._device_info.name}, due to bluetooth a error. Error: {str(err)}"
f"Failed to turn on device {self._device_info.name}, due to bluetooth a error."
f"Error: {str(err)}"
)
return False

Expand All @@ -111,12 +118,14 @@ async def off(self) -> bool:
)
except PlejdNotConnectedError as err:
logging.warning(
f"Device {self._device_info.name} is not connected, cannot turn on. Error: {str(err)}"
f"Device {self._device_info.name} is not connected, cannot turn on."
f"Error: {str(err)}"
)
return False
except (PlejdBluetoothError, PlejdTimeoutError) as err:
logging.warning(
f"Failed to turn on device {self._device_info.name}, due to bluetooth a error. Error: {str(err)}"
f"Failed to turn on device {self._device_info.name}, due to bluetooth a error."
f"Error: {str(err)}"
)
return False

Expand Down Expand Up @@ -150,12 +159,14 @@ async def brightness(self, brightness: int) -> bool:
)
except PlejdNotConnectedError as err:
logging.warning(
f"Device {self._device_info.name} is not connected, cannot turn on. Error: {str(err)}"
f"Device {self._device_info.name} is not connected, cannot turn on."
f"Error: {str(err)}"
)
return False
except (PlejdBluetoothError, PlejdTimeoutError) as err:
logging.warning(
f"Failed to turn on device {self._device_info.name}, due to bluetooth a error. Error: {str(err)}"
f"Failed to turn on device {self._device_info.name}, due to bluetooth a error."
f"Error: {str(err)}"
)
return False

Expand Down
2 changes: 0 additions & 2 deletions ha_plejd_mqtt/mdl/combined_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ async def start(self) -> None:
raise MQTTDeviceError(error_msg) from err

try:
print("Creating BT device")
self._bt_device = await self._create_bt_device()
print("Created BT device")
except BTDeviceError as err:
error_msg = f"Failed to create BT device for {self._device_info.name}"
logging.error(error_msg)
Expand Down
Loading

0 comments on commit b4db06f

Please sign in to comment.