Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup/improvements #54

Merged
merged 13 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
1 change: 0 additions & 1 deletion .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ jobs:
steps:
- uses: "actions/[email protected]"
- uses: home-assistant/actions/hassfest@master

2 changes: 2 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default: true
MD013: false
82 changes: 82 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# For pre-commit.ci
ci:
# Defer autoupdate to quarterly (there is no 'off' button) to have renovate pick up first
autoupdate_schedule: quarterly
submodules: true

default_language_version:
# force all unspecified python hooks to run python3
python: python3.12

repos:
# Run manually in CI skipping the branch checks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: ruff
name: "Ruff-ing code"
args:
- --fix
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: no-commit-to-branch
name: "Verifying git branch exists"
args:
- --branch=main
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
name: "Checking pyupgrade"
args: [--py311-plus]
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
name: "Verifying/updating code using black"
args:
- --safe
- --quiet
files: ^((custom_components|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
name: "Verifying/updating code for spelling issues"
args:
- --ignore-words-list=hass,alot,datas,dof,dur,ether,farenheit,hist,iff,iif,ines,ist,lightsensor,mut,nd,pres,referer,rime,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,iam,incomfort,ba,haa,pullrequests
- --skip="./.*,*.csv,*.json"
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
hooks:
- id: yamllint
name: "Linting yaml"
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
name: "Verifying/updating code with prettier"
- repo: https://github.com/cdce8p/python-typing-update
rev: v0.6.0
hooks:
# Run `python-typing-update` hook manually from time to time
# to update python typing syntax.
# Will require manual work, before submitting changes!
- id: python-typing-update
name: "Verifying code for typing-update"
stages: [manual]
args:
- --py311-plus
- --force
- --keep-updates
files: ^(custom_components|tests)/.+\.py$
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
hooks:
- id: markdownlint
name: "Linting Markdown"
66 changes: 66 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copy of github.com/home-assistant/core .yamllint
# Our addition to truthy
# truthy:
# allowed-values: ['true', 'false', 'on']
ignore: |
azure-*.yml
rules:
braces:
level: error
min-spaces-inside: 0
max-spaces-inside: 1
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
brackets:
level: error
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
colons:
level: error
max-spaces-before: 0
max-spaces-after: 1
commas:
level: error
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
level: error
require-starting-space: true
min-spaces-from-content: 2
comments-indentation:
level: error
document-end:
level: error
present: false
document-start:
level: error
present: false
empty-lines:
level: error
max: 1
max-start: 0
max-end: 1
hyphens:
level: error
max-spaces-after: 1
indentation:
level: error
spaces: 2
indent-sequences: true
check-multi-line-strings: false
key-duplicates:
level: error
line-length: disable
new-line-at-end-of-file:
level: error
new-lines:
level: error
type: unix
trailing-spaces:
level: error
truthy:
allowed-values: ['true', 'false', 'on', 'False'] # 'on' for github actions, 'False' for our services.yaml
level: error
116 changes: 64 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
**:warning::warning::warning:Read the [release notes](<https://github.com/CoMPaTech/stromer/releases>) before upgrading, in case there are BREAKING changes!:warning::warning::warning:**

# Stromer Custom Component for Home Assistant

[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/CoMPaTech/stomer/)
[![CodeFactor](https://www.codefactor.io/repository/github/CoMPaTech/stromer/badge)](https://www.codefactor.io/repository/github/CoMPaTech/stromer)
[![HASSfest](https://github.com/CoMPaTech/stromer/workflows/Validate%20with%20hassfest/badge.svg)](https://github.com/CoMPaTech/stromer/actions)
[![Generic badge](https://img.shields.io/github/v/release/CoMPaTech/stromer)](https://github.com/CoMPaTech/stromer)
**:warning::warning::warning:Read the [release notes](https://github.com/CoMPaTech/stromer/releases) before upgrading, in case there are BREAKING changes!:warning::warning::warning:**

[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/CoMPaTech/stomer/)
[![CodeFactor](https://www.codefactor.io/repository/github/CoMPaTech/stromer/badge)](https://www.codefactor.io/repository/github/CoMPaTech/stromer)
[![HASSfest](https://github.com/CoMPaTech/stromer/workflows/Validate%20with%20hassfest/badge.svg)](https://github.com/CoMPaTech/stromer/actions)
[![Generic badge](https://img.shields.io/github/v/release/CoMPaTech/stromer)](https://github.com/CoMPaTech/stromer)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=CoMPaTech_stromer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=CoMPaTech_stromer)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=CoMPaTech_stromer&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=CoMPaTech_stromer)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=CoMPaTech_stromer&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=CoMPaTech_stromer)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=CoMPaTech_stromer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=CoMPaTech_stromer)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=CoMPaTech_stromer&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=CoMPaTech_stromer)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=CoMPaTech_stromer&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=CoMPaTech_stromer)

[![Open your Home Assistant instance and show your integrations.](https://my.home-assistant.io/badges/integrations.svg)](https://my.home-assistant.io/redirect/integrations/)
[![Open your Home Assistant instance and show your integrations.](https://my.home-assistant.io/badges/integrations.svg)](https://my.home-assistant.io/redirect/integrations/)

## Configuration

Configure this integration the usual way, before starting you will need to retrieve your
Configure this integration the usual way, before starting you will need to retrieve your

- [ ] Client ID
- [ ] Client Secret
Expand All @@ -38,7 +38,7 @@ Basically you'll have to trigger (through automations) the updates yourself. But
- [![Open your automations.](https://my.home-assistant.io/badges/automations.svg)](https://my.home-assistant.io/redirect/automations/)
- Create a new automation, click on the right-top three dots and select 'Edit as YAML'. Don't worry, most of it you will be able to use the visual editor for, it's just that pasting is much easier this way. Do note that you'll have to change the `stromer` part of the bike (or after pasting, select the three dots, go back to visual editor and pick the correct entity).

```
```automation.yml
alias: Stromer cancel updates when locked
description: ''
trigger:
Expand All @@ -59,7 +59,7 @@ mode: single

- Create another automation, same process as above

```
```automation.yml
alias: Stromer start updates when unlocked
description: ''
trigger:
Expand All @@ -80,7 +80,7 @@ mode: single

- And the final one, actually calling the updates (example every 30 seconds). We'll only point to speed, but it will update the other sensors

```
```automation.yml
alias: Stromer update sensors
description: ''
trigger:
Expand All @@ -100,7 +100,7 @@ mode: single

- Final step is adding a button to your dashboard if you want to trigger updates right now. Do note that your bike must be **unlocked** before triggering, otherwise it will 'cancel itself' :) In a dashboard, click the three buttons right top, and add a `button`-card, through `view code editor` paste, switch back to visual editor and customize the below to your taste. Again pointing at speed but it will refresh if the bike is unlocked and trigger the updates helper.

```
```lovelace.yml
show_name: true
show_icon: true
type: button
Expand All @@ -122,50 +122,62 @@ show_state: false

Even though available does not mean it's stable yet, the HA part is solid but the class used to interact with the API is in need of improvement (e.g. better overall handling). This might also warrant having the class available as a module from pypi.

# Changelog
## Changelog

### NOV 2023 [0.2.7]

- Fix to appropriate `device_class` from 0.2.5

### NOV 2023 [0.2.6]

## NOV 2023 [0.2.7]
- Fix to appropriate `device_class` from 0.2.5
- Fix API recall (reverted maintenance approach from 0.2.5) tnx to @simonwolf83

## NOV 2023 [0.2.6]
- Fix API recall (reverted maintenance approach from 0.2.5) tnx to @simonwolf83
### NOV 2023 [0.2.5]

## NOV 2023 [0.2.5]
- Fix unit from W to Wh (thanks @Tinus78) via #46
- Fix unit from W to Wh (thanks @Tinus78) via #46

## OCT 2023 [0.2.4]
- Improve quality

## SEP 2023 [0.2.3]
- Conform to hacs and HA files
- Adding HACS validation
- Improve quality

### SEP 2023 [0.2.3]

- Conform to hacs and HA files
- Adding HACS validation

### SEP 2023 [0.2.2]

- Fix location (i.e. `device_tracker`) reporting

### AUG 2023 [0.2.1]

- Quickfix sensors lost due to some data not available

### MAR 2023 [0.2.0]

- Fix 2023.3 compliance

### APR 2022 [0.1.0]

## SEP 2023 [0.2.2]
- Fix location (i.e. `device_tracker`) reporting
- Include last update sensors

## AUG 2023 [0.2.1]
- Quickfix sensors lost due to some data not available
### APR 2022 [0.0.8]

## MAR 2023 [0.2.0]
- Fix 2023.3 compliancy
- v4 API support
- Data handling and reconnection

## APR 2022 [0.1.0]
- Include last update sensors
### APR 2022 [0.0.7]

## APR 2022 [0.0.8]
- v4 API support
- Data handling and reconnection
- Fix sensory updates
- Potentially fix token expiration

## APR 2022 [0.0.7]
- Fix sensory updates
- Potentially fix token expiration
### MAR 2022 [0.0.4]

## MAR 2022 [0.0.4]
- Initial release
- Creates a device for your bike in Home Assistant
- Refreshed location and other information every 10 minutes
- Initial release
- Creates a device for your bike in Home Assistant
- Refreshed location and other information every 10 minutes

# What does it support?
## What does it support?

- Location
- It inherits zones, but you could also plot your location on a map
Expand All @@ -174,38 +186,38 @@ Even though available does not mean it's stable yet, the HA part is solid but th
- Binary Sensors
- Light-status and Omni-lock status and theft status

# How to install?
## How to install?

- Use [HACS](https://hacs.xyz)
- Navigate to the `Integrations` page and use the three-dots icon on the top right to add a custom repository.
- Use the link to this page as the URL and select 'Integrations' as the category.
- Look for `Stromer` in `Integrations` and install it!

## How to add the integration to HA Core
### How to add the integration to HA Core

For each bike (i.e. api-user) you will have to add it as an integration. Do note that you first have to retrieve your client ID and Secret using some tool like [mitmproxy](https://mitmproxy.org) to fetch these. If you don't know how to do this or what this implies; search from someone who can eloborate on this or do not use this integration. For more details and/or helpful users see [the Dutch Stromer forum](https://www.speedpedelecreview.com/forum/viewtopic.php?f=8&t=1445)

- [ ] In Home Assitant click on `Configuration`
- [ ] In Home Assistant click on `Configuration`
- [ ] Click on `Integrations`
- [ ] Hit the `+` button in the right lower corner
- [ ] Search or browse for 'Stromer e-bike' and click it
- [ ] Enter your e-mail address, password and the client ID and Secret

# Frequently Asked Questions (FAQ)
## Frequently Asked Questions (FAQ)

## I don't like the name of the sensor or the icon
### I don't like the name of the sensor or the icon

You can adjust these in `Configuration`, `Integration` -> `Entities` (e.g. `https://{Your HA address}/config/entities`)

Just click on the device and adjust accordingly!

Please note that you can also click the cogwheel right top corner to rename all entities of a device at once.

## It doesn't work
### It doesn't work

I'm on Discord and used to frequent the Dutch Stromer forum more often, but feel free to add a Bug through the Issues tab on [Github](https://github.com/CoMPaTech/stromer).

## Is it tested?
### Is it tested?

It works on my bike and Home Assistant installation :) Let me know if it works on yours!

Expand Down
8 changes: 6 additions & 2 deletions custom_components/stromer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

SCAN_INTERVAL = timedelta(minutes=10)

PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.DEVICE_TRACKER]
PLATFORMS: list[Platform] = [
Platform.SENSOR,
Platform.BINARY_SENSOR,
Platform.DEVICE_TRACKER,
]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand All @@ -34,7 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except ApiError as ex:
raise ConfigEntryNotReady("Error while communicating to Stromer API") from ex

LOGGER.debug("Stromer entry: {}".format(entry))
LOGGER.debug(f"Stromer entry: {entry}")

# Use Bike ID as unique id
if entry.unique_id is None:
Expand Down
Loading