Skip to content

Commit

Permalink
Run ruff (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeyev authored Aug 31, 2023
1 parent 4cf8210 commit f9389b2
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 41 deletions.
22 changes: 12 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ repos:
hooks:
- id: validate-pyproject


- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.286
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
language_version: python

# - repo: https://github.com/charliermarsh/ruff-pre-commit
# rev: v0.0.285
# - repo: https://github.com/PyCQA/isort
# rev: 5.12.0
# hooks:
# - id: ruff
# args: ["--fix"]
# - id: isort
# language_version: python


- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
Expand Down
3 changes: 1 addition & 2 deletions custom_components/eyeonwater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import asyncio
import logging

from pyonwater import EyeOnWaterAuthError

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import debounce
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from pyonwater import EyeOnWaterAuthError

from .config_flow import create_account_from_config
from .const import (
Expand Down
12 changes: 7 additions & 5 deletions custom_components/eyeonwater/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Support for EyeOnWater binary sensors."""
from dataclasses import dataclass

from pyonwater import Meter

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
Expand All @@ -15,6 +13,7 @@
CoordinatorEntity,
DataUpdateCoordinator,
)
from pyonwater import Meter

from .const import DATA_COORDINATOR, DATA_SMART_METER, DOMAIN, WATER_METER_NAME

Expand Down Expand Up @@ -72,10 +71,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):

sensors = []
for meter in meters:
for description in FLAG_SENSORS:
sensors.append(EyeOnWaterBinarySensor(meter, coordinator, description))
sensors += [
(EyeOnWaterBinarySensor(meter, coordinator, description))
for description in FLAG_SENSORS
]

async_add_entities(sensors, False)
async_add_entities(sensors, update_before_add=False)


class EyeOnWaterBinarySensor(CoordinatorEntity, RestoreEntity, BinarySensorEntity):
Expand Down Expand Up @@ -111,6 +112,7 @@ def __init__(
)

def get_flag(self) -> bool:
"""Get flag value."""
return self.meter.meter_info.reading.flags.__dict__[self.entity_description.key]

@callback
Expand Down
16 changes: 7 additions & 9 deletions custom_components/eyeonwater/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import logging
from typing import Any

from aiohttp import ClientError
from pyonwater import Account, Client, EyeOnWaterAPIError, EyeOnWaterAuthError
import voluptuous as vol

from aiohttp import ClientError
from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import aiohttp_client
from homeassistant.util.unit_system import METRIC_SYSTEM
from pyonwater import Account, Client, EyeOnWaterAPIError, EyeOnWaterAuthError

from .const import DOMAIN

Expand All @@ -29,12 +28,11 @@

def get_hostname_for_country(hass) -> str:
"""Return EOW hostname based on HA country."""
CountryCode = hass.config.country
if CountryCode == "CA":
if hass.config.country == "CA":
return CONF_EOW_HOSTNAME_CA
else:
# There are some users from Europe that use .com domain
return CONF_EOW_HOSTNAME_COM

# There are some users from Europe that use .com domain
return CONF_EOW_HOSTNAME_COM


def create_account_from_config(
Expand Down Expand Up @@ -76,7 +74,7 @@ async def validate_input(hass: core.HomeAssistant, data):
return {"title": account.username}


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
"""Handle a config flow for EyeOnWater."""

VERSION = 1
Expand Down
3 changes: 1 addition & 2 deletions custom_components/eyeonwater/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""EyeOnWater coordinator."""
import logging

from pyonwater import Account, Client, EyeOnWaterAPIError, EyeOnWaterAuthError, Meter

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.update_coordinator import UpdateFailed
from pyonwater import Account, Client, EyeOnWaterAPIError, EyeOnWaterAuthError, Meter

from .sensor import (
async_import_statistics,
Expand Down
3 changes: 1 addition & 2 deletions custom_components/eyeonwater/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
from typing import Any

from pyonwater import DataPoint, Meter

from homeassistant.components.recorder.statistics import async_import_statistics
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.const import UnitOfTemperature
Expand All @@ -14,6 +12,7 @@
CoordinatorEntity,
DataUpdateCoordinator,
)
from pyonwater import DataPoint, Meter

from .const import DATA_COORDINATOR, DATA_SMART_METER, DOMAIN, WATER_METER_NAME
from .statistic_helper import (
Expand Down
3 changes: 1 addition & 2 deletions custom_components/eyeonwater/statistic_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import datetime
import logging

from pyonwater import DataPoint, Meter

from homeassistant.components.recorder import get_instance
from homeassistant.components.recorder.models import StatisticData, StatisticMetaData
from homeassistant.components.recorder.statistics import get_last_statistics
from homeassistant.util import dt as dtutil
from pyonwater import DataPoint, Meter

from .const import WATER_METER_NAME

Expand Down
2 changes: 1 addition & 1 deletion custom_components/eyeonwater/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@callback
def async_register(
hass: HomeAssistant,
_: HomeAssistant,
register: system_health.SystemHealthRegistration,
) -> None:
"""Register system health callbacks."""
Expand Down
19 changes: 13 additions & 6 deletions custom_components/eyeonwater/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
"""Code for testing EOW access with pyonwater package."""

import asyncio
import logging

import aiohttp
from pyonwater import Account, Client

_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.INFO)


async def main():
"""Async main."""
account = Account(
eow_hostname="eyeonwater.com",
username="your EOW login",
password="your EOW password",
username="",
password="",
metric_measurement_system=False,
)
websession = aiohttp.ClientSession()
Expand All @@ -17,14 +24,14 @@ async def main():
await client.authenticate()

meters = await account.fetch_meters(client=client)
print(f"{len(meters)} meters found")
_LOGGER.info("%i meters found", {len(meters)})
for meter in meters:
await meter.read_meter(client=client)
print(f"meter {meter.meter_uuid} shows {meter.reading}")
print(f"meter {meter.meter_uuid} info {meter.meter_info}")
_LOGGER.info("meter %s shows %f", meter.meter_uuid, meter.reading)
_LOGGER.info("meter %s info %s", meter.meter_uuid, meter.meter_info.json())

for d in meter.last_historical_data:
print(str(d["dt"]), d["reading"])
_LOGGER.info("%d-%f", d["dt"], d["reading"])

await websession.close()

Expand Down
15 changes: 13 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ combine_as_imports = true

[tool.ruff]
select = [
#"ALL",
"D1", # pydocstyle errors
"ALL",
"D", # pydocstyle
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # flake8
Expand All @@ -46,12 +46,23 @@ select = [
"ISC", # implicit string concatenation
"UP", # alert you when better syntax is available in your python version
"RUF", # the ruff developer's own rules
"C90", # mccabe
"I", # isort
"N", # pep8-naming
"YTT", # flake8-2020
"ANN", # flake8-annotations
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"B905", # ignore zip() without an explicit strict= parameter, only support with python >3.10
]
fixable = [
"ALL",
"F401", # Remove unused imports.
"NPY001", # Fix numpy types, which are removed in 1.24.
"RUF100", # Remove unused noqa comments.
]

[tool.ruff.per-file-ignores]
"tests/*.py" = ["D1"]
Expand Down

0 comments on commit f9389b2

Please sign in to comment.