Skip to content

Commit

Permalink
Use cookiecutter template
Browse files Browse the repository at this point in the history
  • Loading branch information
CJNE committed Dec 7, 2021
1 parent 3debb38 commit 13d6323
Show file tree
Hide file tree
Showing 25 changed files with 632 additions and 25 deletions.
105 changes: 105 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Contribution guidelines

Contributing to this project should be as easy and transparent as possible, whether it's:

- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features

## Github is used for everything

Github is used to host code, to track issues and feature requests, as well as accept pull requests.

Pull requests are the best way to propose changes to the codebase.

1. Fork the repo and create your branch from `master`.
2. If you've changed something, update the documentation.
3. Make sure your code lints (using black).
4. Test you contribution.
5. Issue that pull request!

## Any contributions you make will be under the MIT Software License

In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.

## Report bugs using Github's [issues](../../issues)

GitHub issues are used to track public bugs.
Report a bug by [opening a new issue](../../issues/new/choose); it's that easy!

## Write bug reports with detail, background, and sample code

**Great Bug Reports** tend to have:

- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can.
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

People _love_ thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style

Use [black](https://github.com/ambv/black) and [prettier](https://prettier.io/)
to make sure the code follows the style.

Or use the `pre-commit` settings implemented in this repository
(see deicated section below).

## Test your code modification

This custom component is based on [integration_blueprint template](https://github.com/custom-components/integration_blueprint).

It comes with development environment in a container, easy to launch
if you use Visual Studio Code. With this container you will have a stand alone
Home Assistant instance running and already configured with the included
[`.devcontainer/configuration.yaml`](./.devcontainer/configuration.yaml)
file.

You can use the `pre-commit` settings implemented in this repository to have
linting tool checking your contributions (see deicated section below).

You should also verify that existing [tests](./tests) are still working
and you are encouraged to add new ones.
You can run the tests using the following commands from the root folder:

```bash
# Create a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install requirements
pip install -r requirements_test.txt
# Run tests and get a summary of successes/failures and code coverage
pytest --durations=10 --cov-report term-missing --cov=custom_components.thermiagenesis tests
```

If any of the tests fail, make the necessary changes to the tests as part of
your changes to the integration.

## Pre-commit

You can use the [pre-commit](https://pre-commit.com/) settings included in the
repostory to have code style and linting checks.

With `pre-commit` tool already installed,
activate the settings of the repository:

```console
$ pre-commit install
```

Now the pre-commit tests will be done every time you commit.

You can run the tests on all repository file with the command:

```console
$ pre-commit run --all-files
```

## License

By contributing, you agree that your contributions will be licensed under its MIT License.
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) 2020 Johan Isacsson
Copyright (c) 2021 cjne

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
96 changes: 93 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,96 @@
[![hacs_badge](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)
# Thermia Genesis

# thermiagenesis
Home assistant custom component for Thermia Inverter/Mega heat pumps
[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
[![License][license-shield]](LICENSE)

[![pre-commit][pre-commit-shield]][pre-commit]
[![Black][black-shield]][black]

[![hacs][hacsbadge]][hacs]
[![Project Maintenance][maintenance-shield]][user_profile]
[![BuyMeCoffee][buymecoffeebadge]][buymecoffee]

[![Discord][discord-shield]][discord]
[![Community Forum][forum-shield]][forum]

This custom component for [home assistant](https://home-assistant.io/) will let you connect your Thermia Diplomat Inverter or
Mega heat pump to Home Assistant using ModbusTCP.

Supports all register values, 300+ entities are avaliable (most are disabled by default)

**This component will set up the following platforms.**

| Platform | Description |
| --------------- | ------------------------------------------------------------------------- |
| `binary_sensor` | Show something `True` or `False`. |
| `sensor` | Show info from Thermia Genesis API. |
| `switch` | Switch something `True` or `False`. |

## Installation

1. Using the tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`).
2. If you do not have a `custom_components` directory (folder) there, you need to create it.
3. In the `custom_components` directory (folder) create a new folder called `thermiagenesis`.
4. Download _all_ the files from the `custom_components/thermiagenesis/` directory (folder) in this repository.
5. Place the files you downloaded in the new directory (folder) you created.
6. Restart Home Assistant
7. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Thermia Genesis"

Using your HA configuration directory (folder) as a starting point you should now also have this:

```text
custom_components/thermiagenesis/translations/en.json
custom_components/thermiagenesis/translations/fr.json
custom_components/thermiagenesis/translations/nb.json
custom_components/thermiagenesis/translations/sensor.en.json
custom_components/thermiagenesis/translations/sensor.fr.json
custom_components/thermiagenesis/translations/sensor.nb.json
custom_components/thermiagenesis/translations/sensor.nb.json
custom_components/thermiagenesis/__init__.py
custom_components/thermiagenesis/api.py
custom_components/thermiagenesis/binary_sensor.py
custom_components/thermiagenesis/config_flow.py
custom_components/thermiagenesis/const.py
custom_components/thermiagenesis/manifest.json
custom_components/thermiagenesis/sensor.py
custom_components/thermiagenesis/switch.py
```

## Configuration is done in the UI

<!---->

## Contributions are welcome!

If you want to contribute to this please read the [Contribution guidelines](CONTRIBUTING.md)

## Credits

This project was generated from [@oncleben31](https://github.com/oncleben31)'s [Home Assistant Custom Component Cookiecutter](https://github.com/oncleben31/cookiecutter-homeassistant-custom-component) template.

Code template was mainly taken from [@Ludeeus](https://github.com/ludeeus)'s [integration_blueprint][integration_blueprint] template

---

[integration_blueprint]: https://github.com/custom-components/integration_blueprint
[black]: https://github.com/psf/black
[black-shield]: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
[buymecoffee]: https://www.buymeacoffee.com/cjne
[buymecoffeebadge]: https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg?style=for-the-badge
[commits-shield]: https://img.shields.io/github/commit-activity/y/cjne/thermiagenesis.svg?style=for-the-badge
[commits]: https://github.com/cjne/thermiagenesis/commits/main
[hacs]: https://hacs.xyz
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badge
[discord]: https://discord.gg/Qa5fW2R
[discord-shield]: https://img.shields.io/discord/330944238910963714.svg?style=for-the-badge
[exampleimg]: example.png
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=for-the-badge
[forum]: https://community.home-assistant.io/
[license-shield]: https://img.shields.io/github/license/cjne/thermiagenesis.svg?style=for-the-badge
[maintenance-shield]: https://img.shields.io/badge/maintainer-%40cjne-blue.svg?style=for-the-badge
[pre-commit]: https://github.com/pre-commit/pre-commit
[pre-commit-shield]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/cjne/thermiagenesis.svg?style=for-the-badge
[releases]: https://github.com/cjne/thermiagenesis/releases
[user_profile]: https://github.com/cjne
1 change: 1 addition & 0 deletions custom_components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Dummy init so that pytest works."""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "Thermia Genesis",
"codeowners": ["@cjne"],
"requirements": ["pythermiagenesis==0.1.5"],
"dependencies": [],
"config_flow": true,
"quality_scale": "platinum",
"issue_tracker": "https://github.com/CJNE/thermiagenesis/issues",
"documentation": "https://github.com/CJNE/thermiagenesis",
"iot_class": "local_polling",
"version": "0.0.6"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "Thermia Inverter/Mega (Genesis)",
"content_in_root": true,
"domains": ["binary_sensor", "sensor", "switch", "climate"]
"name": "Thermia Genesis",
"hacs": "1.6.0",
"domains": ["binary_sensor", "sensor", "switch"],
"iot_class": "Local Polling",
"render_readme": true,
"homeassistant": "0.118.0"
}
17 changes: 0 additions & 17 deletions info.md

This file was deleted.

4 changes: 4 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
homeassistant
pythermiagenesis
flake8
reorder-python-imports
2 changes: 2 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r requirements_dev.txt
pytest-homeassistant-custom-component==0.1.0
46 changes: 46 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
doctests = True
# To work with Black
max-line-length = 88
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# W504 line break after binary operator
ignore =
E501,
W503,
E203,
D202,
W504

[isort]
# https://github.com/timothycrosley/isort
# https://github.com/timothycrosley/isort/wiki/isort-Settings
# splits long import on multiple lines indented by 4 spaces
multi_line_output = 3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
indent = " "
# by default isort don't check module indexes
not_skip = __init__.py
# will group `import x` and `from x import` of the same module.
force_sort_within_sections = true
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
known_first_party = custom_components.thermiagenesis, tests
combine_as_imports = true

[tool:pytest]
addopts = -qq --cov=custom_components.thermiagenesis
console_output_style = count

[coverage:run]
branch = False

[coverage:report]
show_missing = true
fail_under = 100
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for Thermia Genesis integration."""
39 changes: 39 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Global fixtures for Thermia Genesis integration."""
from unittest.mock import patch

import pytest

pytest_plugins = "pytest_homeassistant_custom_component"


# This fixture is used to prevent HomeAssistant from attempting to create and dismiss persistent
# notifications. These calls would fail without this fixture since the persistent_notification
# integration is never loaded during a test.
@pytest.fixture(name="skip_notifications", autouse=True)
def skip_notifications_fixture():
"""Skip notification calls."""
with patch("homeassistant.components.persistent_notification.async_create"), patch(
"homeassistant.components.persistent_notification.async_dismiss"
):
yield


# This fixture, when used, will result in calls to async_get_data to return None. To have the call
# return a value, we would add the `return_value=<VALUE_TO_RETURN>` parameter to the patch call.
@pytest.fixture(name="bypass_get_data")
def bypass_get_data_fixture():
"""Skip calls to get data from API."""
with patch("custom_components.thermiagenesis.ThermiaApiClient.async_get_data"):
yield


# In this fixture, we are forcing calls to async_get_data to raise an Exception. This is useful
# for exception handling.
@pytest.fixture(name="error_on_get_data")
def error_get_data_fixture():
"""Simulate error when retrieving data from API."""
with patch(
"custom_components.thermiagenesis.ThermiaApiClient.async_get_data",
side_effect=Exception,
):
yield
9 changes: 9 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Constants for Thermia Genesis tests."""
from custom_components.thermiagenesis.const import (
CONF_PASSWORD,
)
from custom_components.thermiagenesis.const import (
CONF_USERNAME,
)

MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}
Loading

0 comments on commit 13d6323

Please sign in to comment.