Skip to content

Commit

Permalink
0.3.2 - Release (#446)
Browse files Browse the repository at this point in the history
* Better fix for config flow defaults

* Add more tests for config flow

* Missed a default

* Update config flow text

* Add USPS Exception sensor

* Added tests with sample email

* Add test for download_img function

* Remove commented code

* Handle additional date formats in Amazon emails

* Move init tests to test_init.py

* Fix default for DEFAULT_PATH

* Additional tests

* Add amazon image download error test
* Various path error tests
* Add imap_timeout default test

* Rework DataUpdateCoordinator

* Remove unused variable

* Remove commented code

* Additional typing

* Update release-drafter.yaml

* Remove quotes from amazon foward emails

* Remove garbage test files

* Mail camera (#4)

* Create camera.py

* Add camera platform

* Configuration is done via the config that's already in place

* Remove unused imports

* More unused imports removed

* Add service call

* Add service call to update camera
* Add tests

* Fix docstring

* Update requirements_test.txt

* Update camera.py

* Remove file path since we get it from the coordinator

* Attempt to get camera image to auto update

* Add guards to service call

* Add framework for Amazon camera

* Add 'dev' marking to version

* Clean up unused imports in test

* Put async_update back in

* Add host to camera attributes

* More cleanup

* Rename camera class

* Update camera test

* Add amazon image name rotation

* Add test for amazon image rotation

* Simplify amazon rotating image name generation

* Adjust image_file_name generation for amazon images

* Adjusted test

* Create services.yaml

* Change debug message

* Add amazon deliveries image to camera

* Update markdown files  and hacs.json

* Move images to component directory

* Move images to images directory in custom_component directory
* Change boolean wording
* Add function to copy images to www/mail_and_packages if enabled
* Added test for new function

* typing

* Add cleanup to new image paths

* Adjusted test to confirm cleanup in directories

* Update some translations

* fix missing directory on amazon camera path

* More tests for new function

* Remove unneeded try/catch

* Fix double slash in path

* Path fix

* Update .codecov.yaml

* Add test for check_file_path_access

* Clean up commented code

* More cleanup

* Copy placeholder image into directories

* More debugging messages, update USPS tracking number pattern

* Create no_deliveries.jpg

* Create config.yml

* Change default image for amazon

* Fix no dlivery logic

* Image change

* Update camera.py

* Fix errors

* Removed unneeded logic from image_file_name

* Updated docstrings

* More tests

* Update config.yml

* fix: wrong filename generated

* When no errors occur and no files are found return random filename
* Fixes #413
* Revised tests to check for wrong filename output

* Add additional subject for FedEx

* Add amazon exception sensor

* Adjust tests, handle IMAP errors

* Fix Amazon exception email address

* fix(shipper): Update for new UPS formatted emails

* feat: add UPS exception sensor

* chore: new labeler github action

* chore: adjust release-drafter

* chore: add category to labeler

* fix: resolve bug in amazon exception sensor

* fixes #431

* fix: filter empty list for amazon forwards

* Config flow refactor (#5)

* refactor: create _valididate_user_input function

* Add check in async_setup_entry to fix invalid amazon forwarding email lists

* refactor: update tests and error messages

* chore: add comments

* chore: add missing docstring

* chore: clean up translation files

* refactor: adjust tests, correct spelling

* chore: fix translation file

* chore: update workflow configs

* Update release-drafter.yml

* update the configs again

* fix(shipper): fix usp_delivering sensor

* refactor: code clean up and complexity reduction (#6)

* refactor: code clean up and complexity reduction

* create pylintrc, add missing docstring

* more clean up

* formatting, remove unused import

* clean up unused imports
  • Loading branch information
firstof9 authored Apr 25, 2021
1 parent 350093b commit 9cb8144
Show file tree
Hide file tree
Showing 53 changed files with 5,141 additions and 671 deletions.
10 changes: 9 additions & 1 deletion .github/.codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ coverage:
precision: 2
round: down
range: "70...100"
status:
project:
default:
target: 95%
threshold: 1%
patch:
default:
target: 90%

parsers:
gcov:
Expand All @@ -20,5 +28,5 @@ comment:
require_changes: no

ignore:
- "tests/" # no need to test the tests
- "tests/" # no need to test the tests
- "test.py" # doesn't need testing
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Questions & Support
url: https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/discussions
about: Please ask and answer questions here.
62 changes: 60 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
code-quality: tests/*
documentation: docs/*
# code-quality: tests/*
# documentation: docs/*

# labeler "full" schema

# enable labeler on issues, prs, or both.
enable:
issues: false
prs: true
# comments object allows you to specify a different message for issues and prs

comments:
prs: |
👍 Thanks for the contribution!
🏷 I have applied any labels matching special text in your title and description.
Please review the labels and make any necessary changes.
# Labels is an object where:
# - keys are labels
# - values are objects of { include: [ pattern ], exclude: [ pattern ] }
# - pattern must be a valid regex, and is applied globally to
# title + description of issues and/or prs (see enabled config above)
# - 'include' patterns will associate a label if any of these patterns match
# - 'exclude' patterns will ignore this label if any of these patterns match
labels:
"bugfix":
include:
- '\bfix\b'
exclude: []
"enhancement":
include:
- '\bfeat\b'
- '\brefactor\b'
exclude: []
"feature":
include:
- '\bfeat\b'
exclude: []
"code-quality":
include:
- '\btests\b'
- '\brefactor\b'
exclude: []
"breaking-change":
include:
- '\bBREAKING CHANGE\b'
exclude: []
"shipper":
include:
- '\bshipper\b'
exclude: []
"documentation":
include:
- '\bdocs\b'
exclude: []
"chore":
include:
- '\bchore\b'
exclude: []
3 changes: 3 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ categories:
- "fix"
- "bugfix"
- "bug"
- title: ":wrench: Maintenance :wrench:"
labels:
- "chore"
template: |
[![Downloads for this release](https://img.shields.io/github/downloads/moralmunky/Home-Assistant-Mail-And-Packages/$RESOLVED_VERSION/total.svg)](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/releases/$RESOLVED_VERSION)
Expand Down
26 changes: 21 additions & 5 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
name: "Pull Request Labeler"
# name: "Pull Request Labeler"
# on:
# pull_request:

# jobs:
# triage:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/labeler@main
# with:
# repo-token: "${{ secrets.GITHUB_TOKEN }}"

name: Labeler
on:
pull_request:
pull_request_target:
types: [opened]

jobs:
triage:
labeler:
runs-on: ubuntu-latest

steps:
- uses: actions/labeler@main
- name: Check Labels
id: labeler
uses: jimschubert/labeler-action@v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
1 change: 0 additions & 1 deletion .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- master
- dev

jobs:
update_release_draft:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ notes.txt
.vscode/settings.json
*.pyc
.coverage
ra_0_mailerProvidedImage0
mailerProvidedImage0
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
![GitHub Repo stars](https://img.shields.io/github/stars/moralmunky/Home-Assistant-Mail-And-Packages)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/moralmunky/Home-Assistant-Mail-And-Packages)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)
![Pytest](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/workflows/Pytest/badge.svg?branch=0.3.0)
![CodeQL](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/workflows/CodeQL/badge.svg?branch=0.3.0)
![Validate with hassfest](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/workflows/Validate%20with%20hassfest/badge.svg?branch=0.3.0)
![Pytest](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/workflows/Pytest/badge.svg?branch=master)
![CodeQL](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/workflows/CodeQL/badge.svg?branch=master)
![Validate with hassfest](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/workflows/Validate%20with%20hassfest/badge.svg?branch=master)

![GitHub contributors](https://img.shields.io/github/contributors/moralmunky/Home-Assistant-Mail-And-Packages)
![Maintenance](https://img.shields.io/maintenance/yes/2021)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/moralmunky/Home-Assistant-Mail-And-Packages)
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/moralmunky/Home-Assistant-Mail-And-Packages/0.2.2/0.3.0)
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/moralmunky/Home-Assistant-Mail-And-Packages/0.3.0/master)
![GitHub last commit](https://img.shields.io/github/last-commit/moralmunky/Home-Assistant-Mail-And-Packages)
![Codecov branch](https://img.shields.io/codecov/c/github/moralmunky/Home-Assistant-Mail-And-Packages/0.3.x)
![Codecov branch](https://img.shields.io/codecov/c/github/moralmunky/Home-Assistant-Mail-And-Packages/master)

## About Mail and Packages integration

Expand Down
80 changes: 58 additions & 22 deletions custom_components/mail_and_packages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Mail and Packages Integration."""
import asyncio
import logging
from datetime import timedelta

import async_timeout
from async_timeout import timeout
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_RESOURCES
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import (
CONF_ALLOW_EXTERNAL,
Expand All @@ -19,7 +20,7 @@
DEFAULT_IMAP_TIMEOUT,
DOMAIN,
ISSUE_URL,
PLATFORM,
PLATFORMS,
VERSION,
)
from .helpers import default_image_path, process_emails
Expand Down Expand Up @@ -64,6 +65,16 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
# Sort the resources
updated_config[CONF_RESOURCES] = sorted(updated_config[CONF_RESOURCES])

# Make sure amazon forwarding emails are not a string
if isinstance(updated_config[CONF_AMAZON_FWDS], str):
tmp = updated_config[CONF_AMAZON_FWDS]
tmp_list = []
if "," in tmp:
tmp_list = tmp.split(",")
else:
tmp_list.append(tmp)
updated_config[CONF_AMAZON_FWDS] = tmp_list

if updated_config != config_entry.data:
hass.config_entries.async_update_entry(config_entry, data=updated_config)

Expand All @@ -72,18 +83,13 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
config_entry.options = config_entry.data
config = config_entry.data

async def async_update_data():
"""Fetch data """
async with async_timeout.timeout(config.get(CONF_IMAP_TIMEOUT)):
return await hass.async_add_executor_job(process_emails, hass, config)

coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name=f"Mail and Packages ({config.get(CONF_HOST)})",
update_method=async_update_data,
update_interval=timedelta(minutes=config_entry.data.get(CONF_SCAN_INTERVAL)),
)
# Variables for data coordinator
host = config.get(CONF_HOST)
the_timeout = config.get(CONF_IMAP_TIMEOUT)
interval = config.get(CONF_SCAN_INTERVAL)

# Setup the data coordinator
coordinator = MailDataUpdateCoordinator(hass, host, the_timeout, interval, config)

# Fetch initial data so we have data when entities subscribe
await coordinator.async_refresh()
Expand All @@ -92,12 +98,10 @@ async def async_update_data():
COORDINATOR: coordinator,
}

try:
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, PLATFORM)
hass.config_entries.async_forward_entry_setup(config_entry, platform)
)
except ValueError:
pass

return True

Expand All @@ -107,8 +111,13 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

_LOGGER.debug("Attempting to unload sensors from the %s integration", DOMAIN)

unload_ok = await hass.config_entries.async_forward_entry_unload(
config_entry, PLATFORM
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(config_entry, platform)
for platform in PLATFORMS
]
)
)

if unload_ok:
Expand Down Expand Up @@ -154,7 +163,7 @@ async def async_migrate_entry(hass, config_entry):
else:
updated_config[CONF_AMAZON_FWDS] = []
else:
_LOGGER.warn("Missing configuration data: %s", CONF_AMAZON_FWDS)
_LOGGER.warning("Missing configuration data: %s", CONF_AMAZON_FWDS)

# Force path change
updated_config[CONF_PATH] = "images/mail_and_packages/"
Expand Down Expand Up @@ -187,3 +196,30 @@ async def async_migrate_entry(hass, config_entry):
_LOGGER.debug("Migration to version %s complete", config_entry.version)

return True


class MailDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching mail data."""

def __init__(self, hass, host, the_timeout, interval, config):
"""Initialize."""
self.interval = timedelta(minutes=interval)
self.name = f"Mail and Packages ({host})"
self.timeout = the_timeout
self.config = config
self.hass = hass

_LOGGER.debug("Data will be update every %s", self.interval)

super().__init__(hass, _LOGGER, name=self.name, update_interval=self.interval)

async def _async_update_data(self):
"""Fetch data """
async with timeout(self.timeout):
try:
data = await self.hass.async_add_executor_job(
process_emails, self.hass, self.config
)
except Exception as error:
raise UpdateFailed(error) from error
return data
Loading

0 comments on commit 9cb8144

Please sign in to comment.