Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Feb 8, 2023
1 parent b0f0e97 commit 93c0f06
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 34 deletions.
10 changes: 5 additions & 5 deletions custom_components/jq300/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# Creative Commons BY-NC-SA 4.0 International Public License
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
"""

import asyncio
import logging
from datetime import timedelta
import logging

import async_timeout
import homeassistant.helpers.config_validation as cv
import voluptuous as vol

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_DEVICES, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType

from .api import Jq300Account
Expand Down Expand Up @@ -97,7 +97,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)

try:
with async_timeout.timeout(UPDATE_TIMEOUT):
async with async_timeout.timeout(UPDATE_TIMEOUT):
devices = await account.async_update_devices()
except asyncio.TimeoutError as exc:
raise ConfigEntryNotReady from exc
Expand Down
26 changes: 14 additions & 12 deletions custom_components/jq300/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
Expand All @@ -10,18 +9,19 @@
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

import asyncio
import json
import logging
from datetime import timedelta
from http import HTTPStatus
import json
import logging
from time import monotonic
from typing import Any, Dict, List, Optional, Union
from urllib.parse import urlparse

from aiohttp import ClientSession
import async_timeout
import homeassistant.util.dt as dt_util
import paho.mqtt.client as mqtt
from aiohttp import ClientSession
from requests import PreparedRequest

from homeassistant.const import (
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_BILLION,
Expand All @@ -30,7 +30,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.util import Throttle
from requests import PreparedRequest
import homeassistant.util.dt as dt_util

from .const import (
AVAILABLE_TIMEOUT,
Expand Down Expand Up @@ -362,11 +362,11 @@ def _get_devices_mqtt_topics(self, device_ids: list) -> list:
if not self.devices:
return []

return list(
return [
self.devices[dev_id]["deviceToken"]
for dev_id in device_ids
if dev_id in self.devices
)
]

@property
def active_devices(self) -> List[int]:
Expand Down Expand Up @@ -457,8 +457,10 @@ def _extract_sensors_data(self, device_id, ts_now: int, sensors: dict):
res = {}
for sensor in sensors:
sensor_id = sensor["seq"]
if sensor["content"] is None or sensor["content"] == "" or (
sensor_id not in SENSORS and sensor_id not in BINARY_SENSORS
if (
sensor["content"] is None
or sensor["content"] == ""
or (sensor_id not in SENSORS and sensor_id not in BINARY_SENSORS)
):
continue

Expand Down Expand Up @@ -569,7 +571,7 @@ async def async_update_sensors_or_timeout(self, timeout=UPDATE_TIMEOUT):
"""Update current states of all active devices for account."""
start = monotonic()
try:
with async_timeout.timeout(timeout):
async with async_timeout.timeout(timeout):
await self.async_update_sensors()

except asyncio.TimeoutError as err:
Expand Down
3 changes: 1 addition & 2 deletions custom_components/jq300/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Creative Commons BY-NC-SA 4.0 International Public License
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
Expand Down
3 changes: 1 addition & 2 deletions custom_components/jq300/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Creative Commons BY-NC-SA 4.0 International Public License
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
Expand Down
3 changes: 1 addition & 2 deletions custom_components/jq300/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Creative Commons BY-NC-SA 4.0 International Public License
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
Expand Down
3 changes: 1 addition & 2 deletions custom_components/jq300/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Creative Commons BY-NC-SA 4.0 International Public License
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
Expand Down
3 changes: 1 addition & 2 deletions custom_components/jq300/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Creative Commons BY-NC-SA 4.0 International Public License
# (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/)

"""
Integration of the JQ-300/200/100 indoor air quality meter.
"""Integration of the JQ-300/200/100 indoor air quality meter.
For more details about this component, please refer to
https://github.com/Limych/ha-jq300
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import asyncio
from unittest.mock import patch

import pytest
from asynctest import CoroutineMock
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import pytest

from custom_components.jq300 import Jq300Account
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession

pytest_plugins = "pytest_homeassistant_custom_component" # pylint: disable=invalid-name

Expand Down
2 changes: 1 addition & 1 deletion tests/test_entity.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# pylint: disable=protected-access,redefined-outer-name
"""The test for the entity."""

from homeassistant.exceptions import PlatformNotReady
from pytest import raises

from custom_components.jq300 import Jq300Account
from custom_components.jq300.const import ATTRIBUTION, DOMAIN
from custom_components.jq300.entity import Jq300Entity
from homeassistant.exceptions import PlatformNotReady


async def test_entity_initialization(mock_account: Jq300Account):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# pylint: disable=protected-access,redefined-outer-name
"""The test for the sensor platform."""

import homeassistant.util.dt as dt_util
from homeassistant.core import HomeAssistant

from custom_components.jq300 import Jq300Account
from custom_components.jq300.const import ATTRIBUTION
from custom_components.jq300.sensor import Jq300Sensor
from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util


async def test_entity_initialization(hass: HomeAssistant, mock_account: Jq300Account):
Expand Down

0 comments on commit 93c0f06

Please sign in to comment.