Skip to content

Commit

Permalink
Import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Jan 7, 2025
1 parent 533e070 commit 1683ada
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
11 changes: 11 additions & 0 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
5 changes: 1 addition & 4 deletions custom_components/bhyve/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the BHyve binary sensor platform from a config entry."""

bhyve = hass.data[DOMAIN][entry.entry_id][CONF_CLIENT]

sensors = []
Expand Down Expand Up @@ -79,9 +78,7 @@ def is_on(self):
return self._state == "on"

def _on_ws_data(self, data):
"""
{"last_flood_alarm_at":"2021-08-29T16:32:35.585Z","rssi":-60,"onboard_complete":true,"temp_f":75.2,"provisioned":true,"phy":"le_1m_1000","event":"fs_status_update","temp_alarm_status":"ok","status_updated_at":"2021-08-29T16:33:17.089Z","identify_enabled":false,"device_id":"612ad9134f0c6c9c9faddbba","timestamp":"2021-08-29T16:33:17.089Z","flood_alarm_status":"ok","last_temp_alarm_at":null}
"""
# {"last_flood_alarm_at":"2021-08-29T16:32:35.585Z","rssi":-60,"onboard_complete":true,"temp_f":75.2,"provisioned":true,"phy":"le_1m_1000","event":"fs_status_update","temp_alarm_status":"ok","status_updated_at":"2021-08-29T16:33:17.089Z","identify_enabled":false,"device_id":"612ad9134f0c6c9c9faddbba","timestamp":"2021-08-29T16:33:17.089Z","flood_alarm_status":"ok","last_temp_alarm_at":null}
_LOGGER.info("Received program data update %s", data)
event = data.get("event")
if event == EVENT_FS_ALARM:
Expand Down
6 changes: 4 additions & 2 deletions custom_components/bhyve/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

import json
import logging
from typing import Any
from typing import TYPE_CHECKING, Any

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import CONF_DEVICES, DEVICE_BRIDGE, DOMAIN
from .pybhyve import Client
from .pybhyve.errors import AuthenticationError, BHyveError

if TYPE_CHECKING:
from homeassistant.data_entry_flow import FlowResult

_LOGGER = logging.getLogger(__name__)


Expand Down
6 changes: 3 additions & 3 deletions custom_components/bhyve/pybhyve/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Define an object to interact with the REST API."""

from asyncio import ensure_future
import logging
import re
import time
from asyncio import ensure_future
from typing import Any

from aiohttp import ClientResponseError
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(self, username: str, password: str, session) -> None:
self._username: str = username
self._password: str = password
self._ws_url: str = WS_HOST
self._token: str = None
self._token: str | None = None

self._websocket = None
self._session = session
Expand All @@ -50,7 +50,7 @@ def __init__(self, username: str, password: str, session) -> None:
self._last_poll_landscapes = 0

async def _request(
self, method: str, endpoint: str, params: dict = None, json: dict = None
self, method: str, endpoint: str, params: dict | None = None, json: dict | None = None
) -> list:
"""Make a request against the API."""
url: str = f"{API_HOST}{endpoint}"
Expand Down
8 changes: 4 additions & 4 deletions custom_components/bhyve/pybhyve/websocket.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
import json
import aiohttp

from aiohttp import WSMsgType
import logging
from asyncio import ensure_future
from math import ceil

import aiohttp
from aiohttp import WSMsgType

_LOGGER = logging.getLogger(__name__)

STATE_STARTING = "starting"
Expand Down
11 changes: 5 additions & 6 deletions custom_components/bhyve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import logging
from datetime import timedelta

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.components.sensor.const import SensorDeviceClass, SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_BATTERY_LEVEL, UnitOfTemperature
from homeassistant.const import ATTR_BATTERY_LEVEL, EntityCategory, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.icon import icon_for_battery_level

Expand Down Expand Up @@ -165,7 +164,7 @@ async def async_update(self):
await self._refetch_device()

@staticmethod
def parse_battery_level(battery_data):
def parse_battery_level(battery_data) -> int:
"""
Parses the battery level data and returns the battery level as a percentage.
Expand All @@ -180,8 +179,8 @@ def parse_battery_level(battery_data):
Returns:
float: The battery level as a percentage.
"""
""" # noqa: D401, E501
if not isinstance(battery_data, dict):
_LOGGER.warning("Unexpected battery data, returning 0: %s", battery_data)
return 0
Expand All @@ -201,7 +200,7 @@ def __init__(self, hass, bhyve, device, zone, zone_name):
self._zone = zone
self._zone_id = zone.get("station")

name = "{} zone history".format(zone_name)
name = f"{zone_name} zone history"
_LOGGER.info("Creating history sensor: %s", name)

super().__init__(
Expand Down
11 changes: 5 additions & 6 deletions custom_components/bhyve/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
from typing import Any

import voluptuous as vol
from homeassistant.components.switch import (
DOMAIN as SWITCH_DOMAIN,
)
from homeassistant.components.switch import (
SwitchDeviceClass,
SwitchEntity,
)
from homeassistant.components.switch.const import (
DOMAIN as SWITCH_DOMAIN,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.const import ATTR_ENTITY_ID, EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from homeassistant.util import dt
Expand Down Expand Up @@ -217,7 +216,7 @@ async def async_service_handler(service):
}
entity_ids = service.data.get(ATTR_ENTITY_ID)
component = hass.data.get(SWITCH_DOMAIN)
if entity_ids:
if entity_ids and component is not None:
target_switches = [component.get_entity(entity) for entity in entity_ids]
else:
return
Expand Down

0 comments on commit 1683ada

Please sign in to comment.