Skip to content

Commit

Permalink
Add integration
Browse files Browse the repository at this point in the history
  • Loading branch information
thecode committed May 26, 2022
1 parent 795dbb0 commit 0a0c98d
Show file tree
Hide file tree
Showing 25 changed files with 837 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: "pip"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
open-pull-requests-limit: 10
13 changes: 13 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
change-template: "- #$NUMBER - $TITLE (@$AUTHOR)"
categories:
- title: "⚠ Breaking Changes"
labels:
- "breaking-change"
- title: "⬆️ Dependencies"
collapse-after: 1
labels:
- "dependencies"
template: |
## What’s Changed
$CHANGES
22 changes: 22 additions & 0 deletions .github/workflows/hacs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: HACS Action

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

jobs:
hacs:
name: HACS Action
runs-on: "ubuntu-latest"
steps:
- uses: "actions/[email protected]"
- name: HACS Action
uses: "hacs/action@main"
with:
category: "integration"
14 changes: 14 additions & 0 deletions .github/workflows/hassfest.yml
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/[email protected]"
- uses: "home-assistant/actions/hassfest@master"
15 changes: 15 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Release Drafter

on:
push:
branches:
- main

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "main"
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will install Python dependencies, run tests and lint
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.9"
- "3.10"

steps:
- uses: actions/[email protected]
with:
fetch-depth: 2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements_lint.txt
- name: Lint
run: pre-commit run
101 changes: 101 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Hide sublime text stuff
*.sublime-project
*.sublime-workspace

# Hide some OS X stuff
.DS_Store
.AppleDouble
.LSOverride
Icon

# Thumbnails
._*

# IntelliJ IDEA
.idea
*.iml

# pytest
.pytest_cache
.cache

# GITHUB Proposed Python stuff:
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
.eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
pip-wheel-metadata

# Logs
*.log
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
coverage.xml
nosetests.xml
htmlcov/
test-reports/
test-results.xml
test-output.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

.python-version

# emacs auto backups
*~
*#
*.orig

# venv stuff
pyvenv.cfg
pip-selfcheck.json
venv
.venv
Pipfile*
share/*
Scripts/

# vimmy stuff
*.swp
*.swo
tags
ctags.tmp

# vagrant stuff
virtualization/vagrant/setup_done
virtualization/vagrant/.vagrant
virtualization/vagrant/config

# Visual Studio Code
.vscode/*
!.vscode/cSpell.json
!.vscode/extensions.json
!.vscode/tasks.json

# Typing
.mypy_cache
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
args:
- --max-line-length=500
- --ignore=E203,E266,E501,W503
- --max-complexity=18
- --select=B,C,E,F,W,T4,B9
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: ["--py39-plus"]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
args:
- --multi-line=3
- --trailing-comma
- --force-grid-wrap=0
- --use-parentheses
- --line-width=88
- -p=homeassistant
- --force-sort-within-sections
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.960"
hooks:
- id: mypy
additional_dependencies: [homeassistant==2022.5.5]
31 changes: 31 additions & 0 deletions custom_components/onewire_sysbus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""The 1-Wire SysBus component."""

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from .const import DOMAIN, PLATFORMS
from .onewirehub import OneWireHub


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a 1-Wire hub for a config entry."""
hass.data.setdefault(DOMAIN, {})

onewirehub = OneWireHub(hass)
await onewirehub.initialize(entry)

hass.data[DOMAIN][entry.entry_id] = onewirehub

hass.config_entries.async_setup_platforms(entry, PLATFORMS)

return True


async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(
config_entry, PLATFORMS
):
hass.data[DOMAIN].pop(config_entry.entry_id)

return unload_ok
64 changes: 64 additions & 0 deletions custom_components/onewire_sysbus/config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Config flow for 1-Wire SysBus component."""
from __future__ import annotations

from typing import Any

import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_MOUNT_DIR, DEFAULT_SYSBUS_MOUNT_DIR, DOMAIN
from .onewirehub import InvalidPath, OneWireHub

DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_MOUNT_DIR, default=DEFAULT_SYSBUS_MOUNT_DIR): str,
}
)


async def validate_input_mount_dir(
hass: HomeAssistant, data: dict[str, Any]
) -> dict[str, str]:
"""Validate the user input allows us to connect."""
hub = OneWireHub(hass)
mount_dir = data[CONF_MOUNT_DIR]

# Raises InvalidDir exception on failure
await hub.check_mount_dir(mount_dir)

return {"title": mount_dir}


class OneWireFlowHandler(ConfigFlow, domain=DOMAIN): # type: ignore
"""Handle 1-Wire config flow."""

VERSION = 1

def __init__(self) -> None:
"""Initialize 1-Wire config flow."""

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle 1-Wire config flow start."""
errors: dict[str, str] = {}
if user_input is not None:
# Prevent duplicate entries
await self.async_set_unique_id(user_input[CONF_MOUNT_DIR])
self._abort_if_unique_id_configured()

try:
info = await validate_input_mount_dir(self.hass, user_input)
except InvalidPath:
errors["base"] = "invalid_path"
else:
return self.async_create_entry(title=info["title"], data=user_input)

return self.async_show_form(
step_id="user",
data_schema=DATA_SCHEMA,
errors=errors,
)
19 changes: 19 additions & 0 deletions custom_components/onewire_sysbus/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Constants for 1-Wire component."""
from __future__ import annotations

from homeassistant.const import Platform

CONF_MOUNT_DIR = "mount_dir"
DEFAULT_SYSBUS_MOUNT_DIR = "/sys/bus/w1/devices/"

DOMAIN = "onewire_sysbus"

DEVICE_SUPPORT_SYSBUS = ["10", "22", "28", "3B", "42"]

MANUFACTURER_MAXIM = "Maxim Integrated"
MANUFACTURER_HOBBYBOARDS = "Hobby Boards"
MANUFACTURER_EDS = "Embedded Data Systems"

READ_MODE_FLOAT = "float"

PLATFORMS = [Platform.SENSOR]
Loading

0 comments on commit 0a0c98d

Please sign in to comment.