Skip to content

Commit 0435236

Browse files
committed
Update pyright, fix some imports and tests
1 parent 33c37dd commit 0435236

File tree

8 files changed

+48
-28
lines changed

8 files changed

+48
-28
lines changed

custom_components/hubitat/alarm_control_panel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from homeassistant.components.alarm_control_panel import (
77
AlarmControlPanelEntity,
8+
)
9+
from homeassistant.components.alarm_control_panel.const import (
810
AlarmControlPanelEntityFeature,
911
CodeFormat,
1012
)

custom_components/hubitat/climate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from custom_components.hubitat.hubitatmaker.const import DeviceAttribute
88
from homeassistant.components.climate import (
99
ClimateEntity,
10-
ClimateEntityFeature,
11-
HVACAction,
12-
HVACMode,
1310
)
1411
from homeassistant.components.climate.const import (
1512
ATTR_TARGET_TEMP_HIGH,
@@ -19,6 +16,9 @@
1916
PRESET_AWAY,
2017
PRESET_ECO,
2118
PRESET_HOME,
19+
ClimateEntityFeature,
20+
HVACAction,
21+
HVACMode,
2222
)
2323
from homeassistant.config_entries import ConfigEntry
2424
from homeassistant.const import (

custom_components/hubitat/config_flow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
CONN_CLASS_LOCAL_PUSH,
1212
ConfigEntry,
1313
ConfigFlow,
14+
ConfigFlowResult,
1415
OptionsFlow,
1516
)
1617
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_TEMPERATURE_UNIT
@@ -80,7 +81,7 @@ def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
8081

8182
async def async_step_user(
8283
self, user_input: dict[str, Any] | None = None
83-
) -> FlowResult:
84+
) -> ConfigFlowResult:
8485
"""Handle the user step."""
8586
errors: dict[str, str] = {}
8687

custom_components/hubitat/device_trigger.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Provide automation triggers for certain types of Hubitat device."""
2+
23
import logging
34
from itertools import chain
45
from json import loads
@@ -7,15 +8,21 @@
78
import voluptuous as vol
89

910
from custom_components.hubitat.util import get_hubitat_device_id
10-
from homeassistant.components.automation import (
11-
TriggerActionType,
12-
TriggerInfo,
13-
)
1411
from homeassistant.components.device_automation.exceptions import (
1512
InvalidDeviceAutomationConfig,
1613
)
17-
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
14+
from homeassistant.const import (
15+
CONF_DEVICE_ID,
16+
CONF_DOMAIN,
17+
CONF_EVENT_DATA,
18+
CONF_PLATFORM,
19+
CONF_TYPE,
20+
)
1821
from homeassistant.core import HomeAssistant
22+
from homeassistant.helpers.trigger import (
23+
TriggerActionType,
24+
TriggerInfo,
25+
)
1926
from homeassistant.helpers.typing import ConfigType
2027

2128
from .const import (
@@ -166,9 +173,9 @@ async def async_attach_trigger(
166173

167174
trigger = event.TRIGGER_SCHEMA(
168175
{
169-
event.CONF_PLATFORM: "event",
176+
CONF_PLATFORM: "event",
170177
event.CONF_EVENT_TYPE: H_CONF_HUBITAT_EVENT,
171-
event.CONF_EVENT_DATA: event_data,
178+
CONF_EVENT_DATA: event_data,
172179
}
173180
)
174181

custom_components/hubitat/switch.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,39 +146,37 @@ def is_button_controller(device: Device) -> bool:
146146
)
147147

148148

149+
def is_simple_switch(device: Device, overrides: dict[str, str] | None = None) -> bool:
150+
return is_switch(device, overrides) and not is_energy_meter(device, overrides)
151+
152+
153+
def is_smart_switch(device: Device, overrides: dict[str, str] | None = None) -> bool:
154+
return is_switch(device, overrides) and is_energy_meter(device, overrides)
155+
156+
149157
async def async_setup_entry(
150158
hass: HomeAssistant,
151159
config_entry: ConfigEntry,
152160
async_add_entities: AddEntitiesCallback,
153161
) -> None:
154162
"""Initialize switch devices."""
155163

156-
def _is_simple_switch(
157-
device: Device, overrides: dict[str, str] | None = None
158-
) -> bool:
159-
return is_switch(device, overrides) and not is_energy_meter(device, overrides)
160-
161164
create_and_add_entities(
162165
hass,
163166
config_entry,
164167
async_add_entities,
165168
"switch",
166169
HubitatSwitch,
167-
_is_simple_switch,
170+
is_simple_switch,
168171
)
169172

170-
def _is_smart_switch(
171-
device: Device, overrides: dict[str, str] | None = None
172-
) -> bool:
173-
return is_switch(device, overrides) and is_energy_meter(device, overrides)
174-
175173
create_and_add_entities(
176174
hass,
177175
config_entry,
178176
async_add_entities,
179177
"switch",
180178
HubitatPowerMeterSwitch,
181-
_is_smart_switch,
179+
is_smart_switch,
182180
)
183181

184182
create_and_add_event_emitters(hass, config_entry, is_button_controller)

requirements-dev.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pyrfc3339==1.1
200200
# via acme
201201
pyric==0.1.6.3
202202
# via bluetooth-auto-recovery
203-
pyright==1.1.359
203+
pyright==1.1.378
204204
# via hubitat
205205
pytest==8.0.2
206206
# via pytest-asyncio

requirements.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-e file:.
1313
nodeenv==1.8.0
1414
# via pyright
15-
pyright==1.1.359
15+
pyright==1.1.378
1616
# via hubitat
1717
setuptools==69.5.1
1818
# via nodeenv

tests/test_switch.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ async def test_setup_entry(create_emitters, create_entities) -> None:
1515
create_emitters.return_value = None
1616

1717
from custom_components.hubitat.switch import (
18+
HubitatAlarm,
1819
HubitatPowerMeterSwitch,
1920
HubitatSwitch,
2021
async_setup_entry,
22+
is_alarm,
23+
is_simple_switch,
24+
is_smart_switch,
2125
)
2226

2327
mock_hass = Mock(spec=["async_register"])
@@ -33,22 +37,30 @@ def add_entities(_: List[Entity]) -> None:
3337
assert create_entities.call_count == 3, "expected 3 calls to create entities"
3438

3539
call1 = call(
36-
mock_hass, mock_config_entry, mock_add_entities, "switch", HubitatSwitch
40+
mock_hass,
41+
mock_config_entry,
42+
mock_add_entities,
43+
"switch",
44+
HubitatSwitch,
45+
is_simple_switch,
3746
)
3847
call2 = call(
3948
mock_hass,
4049
mock_config_entry,
4150
mock_add_entities,
4251
"switch",
4352
HubitatPowerMeterSwitch,
53+
is_smart_switch,
4454
)
4555
call3 = call(
4656
mock_hass,
4757
mock_config_entry,
4858
mock_add_entities,
4959
"switch",
50-
HubitatPowerMeterSwitch,
60+
HubitatAlarm,
61+
is_alarm,
5162
)
52-
assert create_entities.has_calls([call1, call2, call3])
63+
64+
create_entities.assert_has_calls([call1, call2, call3])
5365

5466
assert create_emitters.call_count == 1, "expected 1 call to create emitters"

0 commit comments

Comments
 (0)