From b0d413a34237ac4ca3e3f87d6c9368babe983c44 Mon Sep 17 00:00:00 2001 From: YorkshireIoT Date: Sat, 6 Jan 2024 12:01:09 +0000 Subject: [PATCH 1/3] Remove deprecated pylint options, and switch to using ruff --- .devcontainer.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.devcontainer.json b/.devcontainer.json index 8e4d184..9c97d0f 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -13,20 +13,19 @@ "ryanluker.vscode-coverage-gutters", "ms-python.vscode-pylance", "streetsidesoftware.code-spell-checker", - "ms-python.pylint" + "charliermarsh.ruff" ], "settings": { "files.eol": "\n", "editor.tabSize": 4, "python.pythonPath": "/usr/bin/python3", "python.analysis.autoSearchPaths": false, - "python.linting.pylintEnabled": true, - "python.linting.enabled": true, - "python.formatting.provider": "black", - "python.formatting.blackPath": "/usr/local/py-utils/bin/black", "editor.formatOnPaste": false, "editor.formatOnSave": true, "editor.formatOnType": true, + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff" + }, "files.trimTrailingWhitespace": true } } From ac7acec14a856ee9121221cd2a090c090c296314 Mon Sep 17 00:00:00 2001 From: YorkshireIoT Date: Sat, 6 Jan 2024 12:01:50 +0000 Subject: [PATCH 2/3] Fix linting problems --- custom_components/google_fit/__init__.py | 5 +++- custom_components/google_fit/api.py | 26 +++++++++++++++------ custom_components/google_fit/config_flow.py | 18 +++++++++----- custom_components/google_fit/coordinator.py | 2 +- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/custom_components/google_fit/__init__.py b/custom_components/google_fit/__init__.py index caf87d9..107890b 100644 --- a/custom_components/google_fit/__init__.py +++ b/custom_components/google_fit/__init__.py @@ -20,9 +20,12 @@ PLATFORM = Platform.SENSOR + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Google Fit from a config entry.""" - LOGGER.debug("Setting up Google Fit integration from configuration %s", entry.entry_id) + LOGGER.debug( + "Setting up Google Fit integration from configuration %s", entry.entry_id + ) implementation = await async_get_config_entry_implementation(hass, entry) LOGGER.debug("Attempting to create OAuth2 session") diff --git a/custom_components/google_fit/api.py b/custom_components/google_fit/api.py index 3e3c2b6..0e950ef 100644 --- a/custom_components/google_fit/api.py +++ b/custom_components/google_fit/api.py @@ -58,7 +58,9 @@ async def get_resource(self, hass: HomeAssistant) -> FitService: credentials = Credentials(await self.check_and_refresh_token()) LOGGER.debug("Successfully retrieved existing access credentials.") except RefreshError as ex: - LOGGER.warning("Failed to refresh account access token. Starting re-authentication.") + LOGGER.warning( + "Failed to refresh account access token. Starting re-authentication." + ) self.oauth_session.config_entry.async_start_reauth(self.oauth_session.hass) raise ex @@ -125,7 +127,7 @@ def __init__(self): hydration=None, oxygenSaturation=None, ) - self.unknown_sleep_warn = False + self.unknown_sleep_warn = False def _sum_points_int(self, response: FitnessObject) -> int: """Get the most recent integer point value. @@ -141,7 +143,9 @@ def _sum_points_int(self, response: FitnessObject) -> int: counter += value if not found_value: - LOGGER.debug("No int data points found for %s", response.get("dataSourceId")) + LOGGER.debug( + "No int data points found for %s", response.get("dataSourceId") + ) return counter @@ -159,7 +163,9 @@ def _sum_points_float(self, response: FitnessObject) -> float: counter += value if not found_value: - LOGGER.debug("No float data points found for %s", response.get("dataSourceId")) + LOGGER.debug( + "No float data points found for %s", response.get("dataSourceId") + ) return round(counter, 2) @@ -226,9 +232,13 @@ def _parse_sleep(self, response: FitnessObject) -> None: ): sleep_stage = SLEEP_STAGE.get(sleep_type) start_time = int(start_time_ns) / NANOSECONDS_SECONDS_CONVERSION - start_time_str = datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S') + start_time_str = datetime.fromtimestamp(start_time).strftime( + "%Y-%m-%d %H:%M:%S" + ) end_time = int(end_time_ns) / NANOSECONDS_SECONDS_CONVERSION - end_time_str = datetime.fromtimestamp(end_time).strftime('%Y-%m-%d %H:%M:%S') + end_time_str = datetime.fromtimestamp(end_time).strftime( + "%Y-%m-%d %H:%M:%S" + ) if sleep_stage == "Out-of-bed": LOGGER.debug("Out of bed sleep sensor not supported. Ignoring.") @@ -237,7 +247,9 @@ def _parse_sleep(self, response: FitnessObject) -> None: "Google Fit reported an unspecified or unknown value " "for sleep stage between %s and %s. Please report this as a bug to the " "original data provider. This will not be reported in " - "Home Assistant.", start_time_str, end_time_str + "Home Assistant.", + start_time_str, + end_time_str, ) elif sleep_stage is not None: if end_time >= start_time: diff --git a/custom_components/google_fit/config_flow.py b/custom_components/google_fit/config_flow.py index 3e95401..d05d069 100644 --- a/custom_components/google_fit/config_flow.py +++ b/custom_components/google_fit/config_flow.py @@ -68,14 +68,19 @@ async def async_step_reauth_confirm( async def async_oauth_create_entry(self, data: dict[str, Any]) -> FlowResult: """Create an entry for the flow, or update existing entry.""" if self.reauth_entry: - self.logger.debug("Existing authentication flow entry found. " - "Reloading auth config entry: %s ", self.reauth_entry.entry_id) + self.logger.debug( + "Existing authentication flow entry found. " + "Reloading auth config entry: %s ", + self.reauth_entry.entry_id, + ) self.hass.config_entries.async_update_entry(self.reauth_entry, data=data) await self.hass.config_entries.async_reload(self.reauth_entry.entry_id) return self.async_abort(reason="reauth_successful") - self.logger.debug("No existing authentication config flow found. " - "Creating new authentication.") + self.logger.debug( + "No existing authentication config flow found. " + "Creating new authentication." + ) credentials = Credentials(data[CONF_TOKEN][CONF_ACCESS_TOKEN]) def _get_profile() -> dict[str, Any]: @@ -91,8 +96,9 @@ def _check_fit_access() -> FitService: credentials=credentials, static_discovery=False, ) - self.logger.debug("Checking Google Fit access with client id: %s", - credentials.client_id) + self.logger.debug( + "Checking Google Fit access with client id: %s", credentials.client_id + ) sources = ( lib.users() # pylint: disable=no-member .dataSources() diff --git a/custom_components/google_fit/coordinator.py b/custom_components/google_fit/coordinator.py index d5a1098..88b415d 100644 --- a/custom_components/google_fit/coordinator.py +++ b/custom_components/google_fit/coordinator.py @@ -91,7 +91,7 @@ def _get_interval(self, interval_period: int = 0) -> str: * NANOSECONDS_SECONDS_CONVERSION ) else: - start = (int(datetime.today().timestamp()) - interval_period) + start = int(datetime.today().timestamp()) - interval_period start = start * NANOSECONDS_SECONDS_CONVERSION now = int(datetime.today().timestamp() * NANOSECONDS_SECONDS_CONVERSION) return f"{start}-{now}" From 18d398b683b3bb58c9ab7ea15a0e82084b8ca8c7 Mon Sep 17 00:00:00 2001 From: YorkshireIoT Date: Sat, 6 Jan 2024 13:03:02 +0000 Subject: [PATCH 3/3] Use existing ruff-action for lint workflow --- .github/workflows/lint.yml | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index eff287c..2629823 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,20 +10,14 @@ on: jobs: ruff: - name: "Ruff" - runs-on: "ubuntu-latest" + runs-on: ubuntu-latest steps: - - name: "Checkout the repository" - uses: "actions/checkout@v4.1.1" + - uses: actions/checkout@v3 - - name: "Set up Python" - uses: actions/setup-python@v5.0.0 - with: - python-version: "3.11" - cache: "pip" + - name: Ruff Check + uses: chartboost/ruff-action@v1 - - name: "Install requirements" - run: python3 -m pip install -r requirements.txt - - - name: "Run" - run: python3 -m ruff check . + - name: Ruff Format + uses: chartboost/ruff-action@v1 + with: + args: "format --check"