Skip to content

Commit

Permalink
chore: balck format
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Feb 8, 2024
1 parent af399f7 commit f06a4fb
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 19 deletions.
1 change: 1 addition & 0 deletions action/action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Validate a GitHub repository to be used with HACS."""

import asyncio
import json
import os
Expand Down
1 change: 1 addition & 0 deletions custom_components/dual_smart_thermostat/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""const."""

from homeassistant.backports.enum import StrEnum
from homeassistant.const import ATTR_ENTITY_ID
import homeassistant.helpers.config_validation as cv
Expand Down
24 changes: 18 additions & 6 deletions custom_components/dual_smart_thermostat/opening_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Opening Manager for Dual Smart Thermostat."""


import logging

from homeassistant.const import (
Expand Down Expand Up @@ -37,9 +36,14 @@ def __init__(self, hass: HomeAssistant, openings):
@staticmethod
def conform_openings_list(openings: list) -> list:
"""Return a list of openings from a list of entities."""
return [entry
return [
(
entry
if isinstance(entry, dict)
else {ATTR_ENTITY_ID: entry, ATTR_TIMEOUT: None} for entry in openings]
else {ATTR_ENTITY_ID: entry, ATTR_TIMEOUT: None}
)
for entry in openings
]

@staticmethod
def conform_opnening_entities(openings: [TIMED_OPENING_SCHEMA]) -> list:
Expand Down Expand Up @@ -73,7 +77,9 @@ def _is_opening_open(self, opening: TIMED_OPENING_SCHEMA):
):
_is_open = True
_LOGGER.debug(
"Have timeout mode for opening %s, is open: %s", opening, _is_open,
"Have timeout mode for opening %s, is open: %s",
opening,
_is_open,
)
else:
if self.hass.states.is_state(
Expand All @@ -91,9 +97,15 @@ def _is_opening_timed_out(self, opening: TIMED_OPENING_SCHEMA) -> bool:
opening_entity = opening[ATTR_ENTITY_ID]
_is_open = False
if condition.state(
self.hass, opening_entity, STATE_OPEN, opening[ATTR_TIMEOUT],
self.hass,
opening_entity,
STATE_OPEN,
opening[ATTR_TIMEOUT],
) or condition.state(
self.hass, opening_entity, STATE_ON, opening[ATTR_TIMEOUT],
self.hass,
opening_entity,
STATE_ON,
opening[ATTR_TIMEOUT],
):
_is_open = True
return _is_open
1 change: 1 addition & 0 deletions manage/update_manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Update the manifest file."""

import sys
import json
import os
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Global fixtures for schedule_state integration."""

# Fixtures allow you to replace functions with a Mock object. You can perform
# many options via the Mock to reflect a particular behavior from the original
# function that you want to see without going through the function's actual logic.
Expand Down
59 changes: 46 additions & 13 deletions tests/test_thermostat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The tests for the dual_smart_thermostat."""

import asyncio
from datetime import timedelta
import logging
Expand Down Expand Up @@ -381,7 +382,10 @@ async def test_heater_mode_floor_temp(hass, setup_comp_1):

@pytest.mark.parametrize(
["duration", "result_state"],
[(timedelta(seconds=10), STATE_ON), (timedelta(seconds=30), STATE_OFF),],
[
(timedelta(seconds=10), STATE_ON),
(timedelta(seconds=30), STATE_OFF),
],
)
@pytest.mark.asyncio
async def test_heater_mode_cycle(hass, duration, result_state, setup_comp_1):
Expand Down Expand Up @@ -595,7 +599,10 @@ async def test_cooler_mode_tolerance(hass, setup_comp_1):

@pytest.mark.parametrize(
["duration", "result_state"],
[(timedelta(seconds=10), STATE_ON), (timedelta(seconds=30), STATE_OFF),],
[
(timedelta(seconds=10), STATE_ON),
(timedelta(seconds=30), STATE_OFF),
],
)
@pytest.mark.asyncio
async def test_cooler_mode_cycle(hass, duration, result_state, setup_comp_1):
Expand Down Expand Up @@ -658,7 +665,9 @@ async def test_cooler_mode_dual(hass, setup_comp_1):
heater_switch = "input_boolean.heater"
cooler_switch = "input_boolean.cooler"
assert await async_setup_component(
hass, input_boolean.DOMAIN, {"input_boolean": {"heater": None, "cooler": None}},
hass,
input_boolean.DOMAIN,
{"input_boolean": {"heater": None, "cooler": None}},
)

temp_input = "input_number.temp"
Expand Down Expand Up @@ -706,7 +715,10 @@ async def test_cooler_mode_dual(hass, setup_comp_1):

@pytest.mark.parametrize(
["duration", "result_state"],
[(timedelta(seconds=10), STATE_ON), (timedelta(seconds=30), STATE_OFF),],
[
(timedelta(seconds=10), STATE_ON),
(timedelta(seconds=30), STATE_OFF),
],
)
@pytest.mark.asyncio
async def test_cooler_mode_dual_cycle(hass, duration, result_state, setup_comp_1):
Expand All @@ -715,7 +727,9 @@ async def test_cooler_mode_dual_cycle(hass, duration, result_state, setup_comp_1
heater_switch = "input_boolean.heater"
cooler_switch = "input_boolean.cooler"
assert await async_setup_component(
hass, input_boolean.DOMAIN, {"input_boolean": {"heater": None, "cooler": None}},
hass,
input_boolean.DOMAIN,
{"input_boolean": {"heater": None, "cooler": None}},
)

temp_input = "input_number.temp"
Expand Down Expand Up @@ -855,7 +869,9 @@ async def test_heater_cooler_mode(hass, setup_comp_1):
heater_switch = "input_boolean.heater"
cooler_switch = "input_boolean.cooler"
assert await async_setup_component(
hass, input_boolean.DOMAIN, {"input_boolean": {"heater": None, "cooler": None}},
hass,
input_boolean.DOMAIN,
{"input_boolean": {"heater": None, "cooler": None}},
)

temp_input = "input_number.temp"
Expand Down Expand Up @@ -949,7 +965,9 @@ async def test_heater_cooler_mode_floor_temp(hass, setup_comp_1):
heater_switch = "input_boolean.heater"
cooler_switch = "input_boolean.cooler"
assert await async_setup_component(
hass, input_boolean.DOMAIN, {"input_boolean": {"heater": None, "cooler": None}},
hass,
input_boolean.DOMAIN,
{"input_boolean": {"heater": None, "cooler": None}},
)

temp_input = "input_number.temp"
Expand Down Expand Up @@ -1045,7 +1063,10 @@ async def test_heater_cooler_mode_floor_temp(hass, setup_comp_1):

@pytest.mark.parametrize(
["duration", "result_state"],
[(timedelta(seconds=10), STATE_ON), (timedelta(seconds=30), STATE_OFF),],
[
(timedelta(seconds=10), STATE_ON),
(timedelta(seconds=30), STATE_OFF),
],
)
@pytest.mark.asyncio
async def test_heater_cooler_mode_cycle_heat(
Expand Down Expand Up @@ -1116,7 +1137,10 @@ async def test_heater_cooler_mode_cycle_heat(

@pytest.mark.parametrize(
["duration", "result_state"],
[(timedelta(seconds=10), STATE_ON), (timedelta(seconds=30), STATE_OFF),],
[
(timedelta(seconds=10), STATE_ON),
(timedelta(seconds=30), STATE_OFF),
],
)
@pytest.mark.asyncio
async def test_heater_cooler_mode_cycle_cool(
Expand Down Expand Up @@ -1194,7 +1218,9 @@ async def test_heater_cooler_switch_hvac_modes(hass, setup_comp_1):
heater_switch = "input_boolean.heater"
cooler_switch = "input_boolean.cooler"
assert await async_setup_component(
hass, input_boolean.DOMAIN, {"input_boolean": {"heater": None, "cooler": None}},
hass,
input_boolean.DOMAIN,
{"input_boolean": {"heater": None, "cooler": None}},
)

temp_input = "input_number.temp"
Expand Down Expand Up @@ -1245,7 +1271,9 @@ async def test_heater_cooler_mode_tolerances(hass, setup_comp_1):
heater_switch = "input_boolean.heater"
cooler_switch = "input_boolean.cooler"
assert await async_setup_component(
hass, input_boolean.DOMAIN, {"input_boolean": {"heater": None, "cooler": None}},
hass,
input_boolean.DOMAIN,
{"input_boolean": {"heater": None, "cooler": None}},
)

temp_input = "input_number.temp"
Expand Down Expand Up @@ -1379,12 +1407,17 @@ async def async_climate_set_temperature(


async def async_set_hvac_mode(
hass, entity_id="all", hvac_mode=HVACMode.OFF,
hass,
entity_id="all",
hvac_mode=HVACMode.OFF,
):
"""Set new HVAC mode."""
kwargs = {
key: value
for key, value in [(ATTR_ENTITY_ID, entity_id), (ATTR_HVAC_MODE, hvac_mode),]
for key, value in [
(ATTR_ENTITY_ID, entity_id),
(ATTR_HVAC_MODE, hvac_mode),
]
if value is not None
}
_LOGGER.debug("%s start data=%s", SERVICE_SET_HVAC_MODE, kwargs)
Expand Down

0 comments on commit f06a4fb

Please sign in to comment.