Skip to content

Commit

Permalink
Merge pull request #163 from YorkshireIoT/138-vs-code-dev-container-p…
Browse files Browse the repository at this point in the history
…ython-linting-option-deprecated

138 vs code dev container python linting option deprecated
  • Loading branch information
YorkshireIoT authored Jan 6, 2024
2 parents e04be84 + 18d398b commit 3b4eb12
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
9 changes: 4 additions & 5 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ on:

jobs:
ruff:
name: "Ruff"
runs-on: "ubuntu-latest"
runs-on: ubuntu-latest
steps:
- name: "Checkout the repository"
uses: "actions/[email protected]"
- uses: actions/checkout@v3

- name: "Set up Python"
uses: actions/[email protected]
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"
5 changes: 4 additions & 1 deletion custom_components/google_fit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 19 additions & 7 deletions custom_components/google_fit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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.")
Expand All @@ -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:
Expand Down
18 changes: 12 additions & 6 deletions custom_components/google_fit/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/google_fit/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 3b4eb12

Please sign in to comment.