Skip to content

Commit

Permalink
Push first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneNulschDE committed Jan 16, 2024
1 parent c804afc commit 954caf6
Show file tree
Hide file tree
Showing 38 changed files with 1,996 additions and 489 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Validate with hassfest

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: home-assistant/actions/hassfest@master
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release Workflow

on:
release:
types:
- published

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Get integration information
id: information
run: |
name=$(find custom_components/ -type d -maxdepth 1 | tail -n 1 | cut -d "/" -f2)
echo "name=$name" >> $GITHUB_OUTPUT
- name: Adjust version number
shell: bash
run: |
yq -i -o json '.version="${{ github.event.release.tag_name }}"' \
"${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json"
- name: Create zip file for the integration
shell: bash
run: |
cd "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}"
zip ${{ steps.information.outputs.name }}.zip -r ./
- name: Upload the zipfile as a release asset
uses: softprops/action-gh-release@v1
with:
files: ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/${{ steps.information.outputs.name }}.zip
tag_name: ${{ github.event.release.tag_name }}
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ venv.bak/
# mypy
.mypy_cache/


sec_*.txt
.vscode/
/custom_components/mbapi2020/messages/a*
/custom_components/mbapi2020/messages/v*
/custom_components/mbapi2020/messages/m*
/custom_components/mbapi2020/messages/c*
/custom_components/mbapi2020/messages/rc*
# private dev api files
.*-dev
internal_docs/
53 changes: 53 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
files: ^((custom_components/ha-mysmartbike|pylint|script|tests|simulator)/.+)?[^/]+\.py$
# - repo: https://github.com/codespell-project/codespell
# rev: v2.2.2
# hooks:
# - id: codespell
# args:
# - --ignore-words-list=alle,Sie,oder,additionals,alle,alot,bund,currenty,datas,farenheit,falsy,fo,haa,hass,iif,incomfort,ines,ist,nam,nd,pres,pullrequests,resset,rime,ser,serie,te,technik,ue,unsecure,withing,zar
# - --skip="./.*,*.csv,*.json,*.ambr"
# - --quiet-level=2
# exclude_types: [csv, json]
# exclude: ^tests/fixtures/|homeassistant/generated/|tests/components/.*/snapshots/
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
hooks:
- id: yamllint
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: 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!
# pre-commit run --hook-stage manual python-typing-update --all-files
- id: python-typing-update
stages: [manual]
args:
- --py311-plus
- --force
- --keep-updates
files: ^(custom_components/ha-mysmartbike|tests|script|simulator)/.+\.py$
- repo: local
hooks:
- id: const-check-simulator-not-disabled
name: const-check-simulator-not-disabled
entry: "USE_SIMULATOR = True"
language: pygrep
types: [python]
- id: const-check-proxy-not-disabled
name: const-check-proxy-not-disabled
entry: "USE_PROXY = True"
language: pygrep
types: [python]
62 changes: 62 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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: 1
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:
level: error
allowed-values: ['true', 'false', 'on']
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Rene Nulsch
Copyright (c) 2024 Rene Nulsch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
69 changes: 26 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,52 @@
# MySmartBike


# MySmartBike - DEV in progress - NO WORKING Version yet
[![HassFest tests](https://github.com/renenulschde/ha-mysmartbike/workflows/Validate%20with%20hassfest/badge.svg)](https://developers.home-assistant.io/blog/2020/04/16/hassfest)![Validate with HACS](https://github.com/ReneNulschDE/ha-mysmartbike/workflows/Validate%20with%20HACS/badge.svg)

[![HassFest tests](https://github.com/renenulschde/ha-mysmartbike/workflows/Validate%20with%20hassfest/badge.svg)](https://developers.home-assistant.io/blog/2020/04/16/hassfest)

MySmartBike (Male powered e-bikes) platform as a Custom Component for Home Assistant.

IMPORTANT:

* Please login once in the MySmartBike IOS or Android app before you install this component. Make sure you connected your bike in the app

* Tested Countries: DE

### Installation
* First: This is not a Home Assistant Add-On. It's a custom component.

* There is no way to install as the code is not completed yet

* [How to install a custom component?](https://www.google.com/search?q=how+to+install+custom+components+home+assistant)
* [How to install HACS?](https://hacs.xyz/docs/installation/prerequisites)
### Configuration

Use the "Add Integration" in Home Assistant and select "MySmartBike".
- Please login once in the MySmartBike IOS or Android app before you install this component. Make sure you connected your bike(s) in the app

Use your MySmartBike-login email address and your Password.
- Tested Countries: DE

### Optional configuration values
### Features:

See Options dialog in the Integration under Home-Assistant/Configuration/Integration.
- Connect to MySmartBike Cloud and collect registered devices
- Create sensors and device tracker for the found devices

```
Excluded Bikes: comma-separated list of VINs.
```

## Available components
Depends on your own bike.


### Binary Sensors
### Installation

* None
- This is a Home Assistant custom component (not an Add-in).
- Download the folder custom_component and copy it into your Home-Assistant config folder.
- [How to install a custom component?](https://www.google.com/search?q=how+to+install+custom+components+home+assistant)
- Restart HA, Refresh your HA Browser window
- (or add the github repo Url to HACS...)

### Device Tracker

* WIP
### Configuration

### Locks
Use the "Add Integration" in Home Assistant and select "MySmartBike" and follow the following steps:

* None
1. Put in your MySmartBike email address and password in the component setup.

### Sensors

* None
- State of charge (Percent, 0-100)
- Odometer (in meters) - Conversation is WIP

### Diagnostic Sensors

### Diagnostic Sensors
[Diagnostic sensors](https://www.home-assistant.io/blog/2021/11/03/release-202111/#entity-categorization) are hidden by default, check the devices page to see the current values

* None
- None

### Services

* None
- None

### Switches

* None
- None

### Logging

Expand All @@ -78,8 +60,9 @@ logger:
```

### Open Items
* List is too long as we are on version 0.0.1

- List is too long as we are on version 0.0.1

### Useful links

* [Forum post](WIP)
- [Forum post](WIP)
18 changes: 9 additions & 9 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

**Please do not report security vulnerabilities through public GitHub issues.**

Please send an email to [secure-mysmartbike@nulsch.de](mailto:secure-mysmartbike@nulsch.de).
Please send an email to [secure-mysmartbike@nulsch.de](mailto:secure-mysmartbike@nulsch.de).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email and keep in mind this project is the hobby of one person.

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit the issue

This information will help me triage your report more quickly.

If you are reporting for a bug bounty, then this is the wrong project. I do not have a bug bounty programm.
If you are reporting for a bug bounty, then this is the wrong project. I do not have a bug bounty program.

## Preferred Languages

Expand Down
52 changes: 52 additions & 0 deletions custom_components/mysmartbike/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""The Link2Home integration."""
from __future__ import annotations

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DOMAIN, LOGGER, MYSMARTBIKE_PLATFORMS
from .coordinator import MySmartBikeDataUpdateCoordinator


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Set up Link2Home from a config entry."""

username: str = config_entry.options[CONF_USERNAME]
password: str = config_entry.options[CONF_PASSWORD]

websession = async_get_clientsession(hass)

coordinator = MySmartBikeDataUpdateCoordinator(hass, websession, username, password)
await coordinator.async_init()

await coordinator.async_config_entry_first_refresh()

hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator

await hass.config_entries.async_forward_entry_setups(config_entry, MYSMARTBIKE_PLATFORMS)

config_entry.add_update_listener(config_entry_update_listener)

return True


async def config_entry_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update listener, called when the config entry options are changed."""
LOGGER.debug("Start config_entry_update_listener")
await hass.config_entries.async_reload(entry.entry_id)


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
LOGGER.debug("Start async_unload_entry")

# coordinator: MySmartBikeDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]

unload_ok = await hass.config_entries.async_unload_platforms(entry, MYSMARTBIKE_PLATFORMS)

if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
Loading

0 comments on commit 954caf6

Please sign in to comment.