Skip to content

Commit

Permalink
0.3.3 - Release (#528)
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

* chore: add IoT class to manifest.json

* Fix tests

* Enable custom integration tests

* Initial start to custom no mail

* Update config flow to accept custom no mail image
* fix: sensor error when self.data is None

* Update config flow test

* Added new default option to config flow test
* Removed unused import

* Add custom image paths to functions

* Add tests for new custom image feature

* Options flow fix

* Fix options flow
* Add tests for options for for new feature

* More tests

* adjust the default custom image

* chore: workflow changes

* Disable labeler
* Use release-drafter auto labeler
* Add PR Linter for semantic pr titles

* Add available property to camera entities

* fix typo

* Add more debugging

* fix test

* chore: adjust release-drafter config

* fix: config flow not loading new config

* fix: adjust file path generation for new option

* Fix/adjust tests to properly test new option
* Add a more debugging to camera.py

* fix(translations): adjust wording on new option

* fix: adjust image_file_name function

* Add more debugging
* Minor refactor on "no mail" image
* Add more checks to tests

* fix: fix nomail image in get_mails function

* Better error handling

* More error handling
* More debug messages
* Update test requirements

* update tests

* more tests

* Update USPS delivering subject

* Fixes #473

* Add code-quality to release drafter

* Attempt to parse international dates

* Potential fix #478

* make sure date is processed

* fix: better international handling of amazon

* added additional international tests

* update to install Italian locale

* Update pytest.yaml

* Add additional language flag

* Update const.py

* fix: better errors for intervals too low

* Fixes #483

* Update USPS tracking number regex

* fix test

* fix: tracking number with multiple subjects search

* fix: better fix for #488

* extend the tracking numbers list

* make sure not to count the tracking numbers twice

* condense code

* fix: user input malformed bug in config flow

* update the function where missing

* Fix UPS Tracking

* Add ConfigEntryNotReady if we can't pull data on startup
* Change to use self._attr_unit_of_measurement

* Fix tests

* Update pytest.yaml

* Fix tests

* more test fixes

* Update test_helpers.py

* fix: properly handle HTML emails

* refactor: small code cleanup

* Adjust tests

* refactor: more cleanup

* Adjust tests

* Adjust local warnings to info and adjust amazon count

* fix: don't try to update camera if data is missing

* docs: update README

* ignore bandit warning

* refactor: swap state for native_value

* add missing entity classes

* spelling

* fix: requesting camera height and width

* Update release-drafter.yml

* fix: adjust find_text function

* related to #515

* fix: pass the list directly to find_text

* related to #515

* chore: formatting

* tests: add fedex out for delivery

* refactor: utilize walrus operator

* replace amazon icon

* feat: add error message if coordinator fails on startup

* fix: list index out of range error

* fixes #525

* Update en.json
  • Loading branch information
firstof9 authored Oct 20, 2021
1 parent 9cb8144 commit d976d89
Show file tree
Hide file tree
Showing 24 changed files with 2,874 additions and 365 deletions.
21 changes: 20 additions & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@ name-template: "$RESOLVED_VERSION"
tag-template: "$RESOLVED_VERSION"
change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
sort-direction: ascending
autolabeler:
- label: "chore"
title:
- "/chore:/i"
- label: "bugfix"
title:
- "/fix:/i"
- label: "feature"
title:
- "/feat:/i"
- label: "enhancement"
title:
- "/refactor:/i"
- label: "code-quality"
title:
- "/tests:/i"
categories:
- title: ":boom: Breaking Change :boom:"
labels:
- "breaking-change"
- title: ":zap: Enhancments :zap:"
- title: ":zap: Enhancements :zap:"
labels:
- "enhancement"
- title: ":sparkles: New Features :sparkles:"
Expand All @@ -20,6 +36,9 @@ categories:
- title: ":wrench: Maintenance :wrench:"
labels:
- "chore"
- title: ":mortar_board: Code Quality :mortar_board:"
labels:
- "code-quality"
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: 13 additions & 13 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
# with:
# repo-token: "${{ secrets.GITHUB_TOKEN }}"

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

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

steps:
- name: Check Labels
id: labeler
uses: jimschubert/labeler-action@v2
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
# steps:
# - name: Check Labels
# id: labeler
# uses: jimschubert/labeler-action@v2
# with:
# GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
18 changes: 18 additions & 0 deletions .github/workflows/pr-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
steps:
# Please look up the latest version from
# https://github.com/amannn/action-semantic-pull-request/releases
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements_test.txt
sudo apt-get update
sudo apt-get -y install language-pack-it
- name: Generate coverage report
run: |
python -m pytest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- master
- dev
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [opened, reopened, synchronize]

jobs:
update_release_draft:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
![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.3.0/master)
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/moralmunky/Home-Assistant-Mail-And-Packages/0.3.2/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/master)

Expand Down
10 changes: 8 additions & 2 deletions custom_components/mail_and_packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_RESOURCES
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import (
Expand All @@ -29,7 +30,7 @@


async def async_setup(hass, config_entry):
""" Disallow configuration via YAML """
"""Disallow configuration via YAML"""

return True

Expand Down Expand Up @@ -94,6 +95,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
# Fetch initial data so we have data when entities subscribe
await coordinator.async_refresh()

# Raise ConfEntryNotReady if coordinator didn't update
if not coordinator.last_update_success:
_LOGGER.error("Error updating sensor data: %s", coordinator.last_exception)
raise ConfigEntryNotReady

hass.data[DOMAIN][config_entry.entry_id] = {
COORDINATOR: coordinator,
}
Expand Down Expand Up @@ -214,7 +220,7 @@ def __init__(self, hass, host, the_timeout, interval, config):
super().__init__(hass, _LOGGER, name=self.name, update_interval=self.interval)

async def _async_update_data(self):
"""Fetch data """
"""Fetch data"""
async with timeout(self.timeout):
try:
data = await self.hass.async_add_executor_job(
Expand Down
37 changes: 32 additions & 5 deletions custom_components/mail_and_packages/camera.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Camera that loads a picture from a local file."""
from __future__ import annotations

import logging
import os

Expand All @@ -14,6 +16,8 @@
ATTR_IMAGE_PATH,
CAMERA,
CAMERA_DATA,
CONF_CUSTOM_IMG,
CONF_CUSTOM_IMG_FILE,
COORDINATOR,
DOMAIN,
SENSOR_NAME,
Expand All @@ -30,7 +34,10 @@ async def async_setup_entry(hass, config, async_add_entities):

coordinator = hass.data[DOMAIN][config.entry_id][COORDINATOR]
camera = []
file_path = f"{os.path.dirname(__file__)}/mail_none.gif"
if not config.data.get(CONF_CUSTOM_IMG):
file_path = f"{os.path.dirname(__file__)}/mail_none.gif"
else:
file_path = config.data.get(CONF_CUSTOM_IMG_FILE)

for variable in CAMERA_DATA:
temp_cam = MailCam(hass, variable, config, coordinator, file_path)
Expand Down Expand Up @@ -93,8 +100,15 @@ def __init__(
self._coordinator = coordinator
self._host = config.data.get(CONF_HOST)
self._unique_id = config.entry_id

async def async_camera_image(self):
self._no_mail = (
None
if not config.data.get(CONF_CUSTOM_IMG)
else config.data.get(CONF_CUSTOM_IMG_FILE)
)

async def async_camera_image(
self, width: int | None = None, height: int | None = None
) -> bytes | None:
"""Return image response."""
try:
with open(self._file_path, "rb") as file:
Expand All @@ -117,16 +131,24 @@ def update_file_path(self) -> None:
"""Update the file_path."""

_LOGGER.debug("Camera Update: %s", self._type)
_LOGGER.debug("Custom No Mail: %s", self._no_mail)

if self._coordinator.data is None:
_LOGGER.warning("Unable to update camera image, no data.")
return

if self._type == "usps_camera":
# Update camera image for USPS informed delivery imgages
# Update camera image for USPS informed delivery images
image = self._coordinator.data[ATTR_IMAGE_NAME]

if ATTR_IMAGE_PATH in self._coordinator.data.keys():
path = self._coordinator.data[ATTR_IMAGE_PATH]
file_path = f"{self.hass.config.path()}/{path}{image}"
else:
file_path = f"{os.path.dirname(__file__)}/mail_none.gif"
if self._no_mail is None:
file_path = f"{os.path.dirname(__file__)}/mail_none.gif"
else:
file_path = self._no_mail

elif self._type == "amazon_camera":
# Update camera image for Amazon deliveries
Expand Down Expand Up @@ -172,3 +194,8 @@ def should_poll(self) -> bool:
async def async_update(self):
"""Update camera entity and refresh attributes."""
self.update_file_path()

@property
def available(self) -> bool:
"""Return if entity is available."""
return self._coordinator.last_update_success
Loading

0 comments on commit d976d89

Please sign in to comment.