Skip to content

Commit

Permalink
Merge pull request #14 from connorgallopo/hass-actions
Browse files Browse the repository at this point in the history
Lint code and add HACS workflow
  • Loading branch information
connorgallopo committed Jun 10, 2024
2 parents a7112e8 + 3aea8b9 commit aa32494
Show file tree
Hide file tree
Showing 23 changed files with 474 additions and 479 deletions.
85 changes: 0 additions & 85 deletions .github/workflows/tests.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Validate

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
validate-hacs:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ repos:
- id: black
name: black
entry: black
language: system
language: python
types: [python]
require_serial: true
additional_dependencies: [black==22.3.0, click==8.0.4]
- id: flake8
name: flake8
entry: flake8
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

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

| Platform | Description |
| --------------- | ------------------------------------------------------------------------- |
| `sensor` | Show info from leslies_pool API. |
| Platform | Description |
| -------- | -------------------------------- |
| `sensor` | Show info from leslies_pool API. |

**The component will set up the following sensors:**

- Free Chlorine - PPM
- Total Chlorine - PPM
- PH - pH
Expand All @@ -34,7 +35,6 @@
- Phosphates - PPB
- Salt - PPM


## Installation - Automatic (REQUIRES HACS)

1. Add this repository URL to HACS custom repositories as an Integration
Expand All @@ -53,6 +53,7 @@
7. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "leslies_pool"

## Setup

1. Provide the Username and Password for your leslie's account. These are used to auth and refresh cookies
2. Input the Water Test URL. This can be found by navigating [here](https://lesliespool.com/on/demandware.store/Sites-lpm_site-Site/en_US/PoolProfile-Landing) once logged in, and then by clicking on "Water Tests" for the pool you want to integrate. The water test URL can be copied from the URL bar once you have navigated there. This URL contains the Pool ID and Pool Name which are needed to make the API calls to fetch the data.
3. Set a polling rate (Seconds).
Expand Down
1 change: 0 additions & 1 deletion custom_components/leslies_pool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Initialize Leslie's Pool Water Tests integration."""

from __future__ import annotations

from homeassistant.config_entries import ConfigEntry
Expand Down
4 changes: 2 additions & 2 deletions custom_components/leslies_pool/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""API client for Leslie's Pool Water Tests."""

from bs4 import BeautifulSoup, Tag
import requests
from bs4 import BeautifulSoup
from bs4 import Tag


class LesliesPoolApi:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/leslies_pool/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Config flow for Leslie's Pool Water Tests integration."""

from __future__ import annotations

import logging
import re
from typing import Any

import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD
from homeassistant.const import CONF_SCAN_INTERVAL
from homeassistant.const import CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError

Expand Down
7 changes: 4 additions & 3 deletions custom_components/leslies_pool/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"domain": "leslies_pool",
"name": "Leslie's Pool Water Tests",
"codeowners": ["@connorgallopo"],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/connorgallopo/leslies-pool",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/connorgallopo/leslies-pool/issues",
"dependencies": [],
"config_flow": true,
"codeowners": ["@connorgallopo"],
"requirements": ["beautifulsoup4==4.12.3", "requests==2.31.0"],
"version": "1.0.0"
}
2 changes: 1 addition & 1 deletion custom_components/leslies_pool/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
beautifulsoup4==4.12.3
requests==2.31.0
requests==2.31.0
10 changes: 5 additions & 5 deletions custom_components/leslies_pool/sensor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Sensor platform for Leslie's Pool Water Tests."""

from datetime import timedelta
import logging
from datetime import timedelta

import requests

from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import UpdateFailed

from .const import DOMAIN

Expand Down
40 changes: 17 additions & 23 deletions custom_components/leslies_pool/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
{
"config": {
"error": {
"invalid_auth": "Authentication failed.",
"invalid_url": "The provided URL is invalid.",
"unknown": "An unknown error occurred."
},
"step": {
"user": {
"data": {
"password": "Password",
"scan_interval": "Polling Interval (seconds)",
"username": "Username",
"water_test_url": "Water Test URL"
},
"description": "Set up your Leslie's Pool integration.",
"description_placeholders": {
"password": "Enter your password",
"scan_interval": "300",
"username": "Enter your username",
"water_test_url": "https://lesliespool.com/on/demandware.store/Sites-lpm_site-Site/en_US/WaterTest-Landing?poolProfileId=XXXX&poolName=XXXX"
},
"title": "Leslie's Pool Water Tests"
}
"error": {
"invalid_auth": "Authentication failed.",
"invalid_url": "The provided URL is invalid.",
"unknown": "An unknown error occurred."
},
"step": {
"user": {
"data": {
"password": "Password",
"scan_interval": "Polling Interval (seconds)",
"username": "Username",
"water_test_url": "Water Test URL"
},
"description": "Set up your Leslie's Pool integration.",
"title": "Leslie's Pool Water Tests"
}
}
}
}
}
7 changes: 0 additions & 7 deletions custom_components/leslies_pool/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
"username": "Nom d'utilisateur",
"water_test_url": "URL du test de l'eau"
},
"description": "Configurez votre intégration Leslie's Pool.",
"description_placeholders": {
"password": "Entrez votre mot de passe",
"scan_interval": "300",
"username": "Entrez votre nom d'utilisateur",
"water_test_url": "https://lesliespool.com/on/demandware.store/Sites-lpm_site-Site/en_US/WaterTest-Landing?poolProfileId=XXXX&poolName=XXXX"
},
"title": "Tests de l'eau de Leslie's Pool"
}
}
Expand Down
7 changes: 0 additions & 7 deletions custom_components/leslies_pool/translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
"username": "Brukernavn",
"water_test_url": "Vanntest-URL"
},
"description": "Konfigurer din Leslie's Pool-integrasjon.",
"description_placeholders": {
"password": "Skriv inn ditt passord",
"scan_interval": "300",
"username": "Skriv inn ditt brukernavn",
"water_test_url": "https://lesliespool.com/on/demandware.store/Sites-lpm_site-Site/en_US/WaterTest-Landing?poolProfileId=XXXX&poolName=XXXX"
},
"title": "Leslie's Pool Vanntester"
}
}
Expand Down
2 changes: 0 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "Leslie's Pool Water Tests",
"hacs": "1.6.0",
"domains": ["sensor"],
"iot_class": "Cloud Polling",
"homeassistant": "0.118.0"
}
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
beautifulsoup4==4.12.3
requests==2.31.0
requests==2.31.0
black==22.3.0
click==8.0.4
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Tests for leslies_pool integration."""
"""Tests for the Leslie's Pool Water Tests integration."""
42 changes: 9 additions & 33 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
"""Global fixtures for leslies_pool integration."""
"""Common fixtures for the Leslie's Pool Water Tests tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock
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.leslies_pool.LesliesPoolApiClient.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."""
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"custom_components.leslies_pool.LesliesPoolApiClient.async_get_data",
side_effect=Exception,
):
yield
"homeassistant.components.leslies_pool.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
8 changes: 2 additions & 6 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Constants for leslies_pool tests."""
from custom_components.leslies_pool.const import (
CONF_PASSWORD,
)
from custom_components.leslies_pool.const import (
CONF_USERNAME,
)
from custom_components.leslies_pool.const import CONF_PASSWORD
from custom_components.leslies_pool.const import CONF_USERNAME

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

0 comments on commit aa32494

Please sign in to comment.