Skip to content

Commit

Permalink
Adds license. Adds devcontainer for easier development. fixes #2 and f…
Browse files Browse the repository at this point in the history
…ixes #4
  • Loading branch information
Jon Kristian Nilsen committed Feb 28, 2023
1 parent 771b628 commit e250495
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 7 deletions.
36 changes: 36 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "ludeeus/integration_blueprint",
"image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye",
"postCreateCommand": "scripts/setup",
"forwardPorts": [
8123
],
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"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,
"files.trimTrailingWhitespace": true
}
}
},
"remoteUser": "vscode",
"features": {
"rust": "latest"
}
}
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,31 @@ eggs
*.orig
.idea

# vscode
# artifacts
__pycache__
.pytest*
*.egg-info
*/build/*
*/dist/*


# misc
.coverage
.vscode
coverage.xml


# Home Assistant configuration
.cloud
.HA_VERSION
.storage
automations.yaml
blueprints
configuration.yaml
deps
home-assistant_v2*
home-assistant.log*
tts
scenes.yaml
scripts.yaml
secrets.yaml
61 changes: 61 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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) to make sure the code follows the style.

## Test your code modification

This custom component uses [integration_blueprint template](https://github.com/ludeeus/integration_blueprint) devcontainer.

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
[`configuration.yaml`](./configuration.yaml)
file.

## License

By contributing, you agree that your contributions will be licensed under its MIT License.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 - 2023 Joakim Sørensen @ludeeus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 8 additions & 1 deletion custom_components/casatunes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Fetch initial data so we have data when entities subscribe
await coordinator.async_config_entry_first_refresh()

hass.config_entries.async_setup_platforms(entry, PLATFORMS)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))

return True

Expand All @@ -68,6 +69,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok


async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)


class CasaTunesDataUpdateCoordinator(DataUpdateCoordinator[CasaTunes]):
"""Class to manage fetching data from the API."""

Expand Down
15 changes: 11 additions & 4 deletions custom_components/casatunes/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
class UnknownMediaType(BrowseError):
"""Unknown media type."""


BROWSE_LIMIT = 1000

_LOGGER = logging.getLogger(__name__)


async def build_item_response(zone_id, casa_server, media_content_type=None, media_content_id=None):
async def build_item_response(
zone_id, casa_server, media_content_type=None, media_content_id=None
):
"""Implement the websocket media browsing helper."""
try:
_LOGGER.debug("browse_media: %s: %s", media_content_type, media_content_id)
Expand All @@ -39,7 +42,11 @@ async def item_payload(casa_server, item):
thumbnail = None
image_id = item.get("ArtworkURI")
if image_id:
thumbnail = image_id if image_id.startswith("http://") else await casa_server.data.get_image(image_id)
thumbnail = (
image_id
if image_id.startswith(("http://", "https://"))
else await casa_server.data.get_image(image_id)
)

media_content_id = item["ID"]

Expand Down Expand Up @@ -92,8 +99,8 @@ async def library_payload(casa_server, zone_id, media_content_id):
_LOGGER.debug("Result detail %s", result_detail)

list_title = "Browse Media"
if 'Title' in result_detail:
list_title = result_detail['Title']
if "Title" in result_detail:
list_title = result_detail["Title"]

library_info = BrowseMedia(
title=list_title,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/casatunes/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://github.com/jonkristian/casatunes",
"issue_tracker": "https://github.com/jonkristian/casatunes/issues",
"version": "0.1.3",
"version": "0.1.4",
"requirements": [
"pycasatunes==0.1.2"
],
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pip>=21.0,<23.1
colorlog
homeassistant
8 changes: 8 additions & 0 deletions scripts/develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

# Start Home Assistant
hass -c . --debug
7 changes: 7 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

python3 -m pip install --requirement requirements.txt

0 comments on commit e250495

Please sign in to comment.