Skip to content

Commit 9758712

Browse files
committed
fix precommit
1 parent a959996 commit 9758712

File tree

11 files changed

+54
-30
lines changed

11 files changed

+54
-30
lines changed

.github/workflows/lint_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Lint & Test
33
on:
44
pull_request:
55
push:
6-
branches: [base]
6+
branches: [base]
77

88
jobs:
99
pre-commit:

custom_components/ttlock/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@
4242
from .models import WebhookEvent
4343
from .services import Services
4444

45-
PLATFORMS: list[Platform] = [Platform.LOCK, Platform.SENSOR, Platform.BINARY_SENSOR, Platform.SWITCH]
45+
PLATFORMS: list[Platform] = [
46+
Platform.LOCK,
47+
Platform.SENSOR,
48+
Platform.BINARY_SENSOR,
49+
Platform.SWITCH,
50+
]
4651

4752
_LOGGER = logging.getLogger(__name__)
4853

custom_components/ttlock/api.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ async def get_sensor(self, lock_id: int) -> Sensor:
164164
_LOGGER.error("Error setting up sensor", lock_id, res["errmsg"])
165165
pass
166166
return Sensor.parse_obj(res)
167-
168-
167+
169168
async def get_lock_state(self, lock_id: int) -> LockState:
170169
"""Get the state of a lock."""
171170
async with GW_LOCK:
@@ -272,7 +271,7 @@ async def delete_passcode(self, lock_id: int, passcode_id: int) -> bool:
272271
return False
273272

274273
return True
275-
274+
276275
async def set_auto_lock(self, lock_id: int, seconds: int) -> bool:
277276
"""Set the AutoLock feature of the lock."""
278277

custom_components/ttlock/binary_sensor.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
import logging
55

6-
from homeassistant.components.binary_sensor import BinarySensorDeviceClass, BinarySensorEntity
6+
from homeassistant.components.binary_sensor import (
7+
BinarySensorDeviceClass,
8+
BinarySensorEntity,
9+
)
710
from homeassistant.config_entries import ConfigEntry
811
from homeassistant.core import HomeAssistant
912
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@@ -32,15 +35,18 @@ async def async_setup_entry(
3235
]
3336
)
3437

38+
3539
class Sensor(BaseLockEntity, BinarySensorEntity):
3640
"""Current sensor state."""
41+
3742
_attr_device_class = BinarySensorDeviceClass.DOOR
3843

3944
def _update_from_coordinator(self) -> None:
4045
"""Fetch state of device."""
4146
self._attr_name = f"{self.coordinator.data.name} Sensor"
4247
self._attr_is_on = self.coordinator.data.opened
4348

49+
4450
class PassageMode(BaseLockEntity, BinarySensorEntity):
4551
"""Current passage mode state."""
4652

custom_components/ttlock/const.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
SVC_CONFIG_PASSAGE_MODE = "configure_passage_mode"
2222
SVC_CREATE_PASSCODE = "create_passcode"
2323
SVC_CLEANUP_PASSCODES = "cleanup_passcodes"
24-
SVC_SET_AUTOLOCK = "set_autolock"
24+
SVC_SET_AUTOLOCK = "set_autolock"

custom_components/ttlock/coordinator.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LockState:
4444
opened: bool | None = None
4545
sensor_battery: int | None = None
4646

47-
auto_lock_seconds: int | None = None
47+
auto_lock_seconds: int = 0
4848
auto_lock: bool | None = None
4949
passage_mode_config: PassageModeConfig | None = None
5050

@@ -74,9 +74,10 @@ def auto_lock_delay(self, current_date: datetime) -> int | None:
7474

7575
if self.passage_mode_active(current_date):
7676
return None
77-
77+
7878
return self.auto_lock_seconds
7979

80+
8081
@contextmanager
8182
def lock_action(controller: LockUpdateCoordinator):
8283
"""Wrap a lock action so that in-progress state is managed correctly."""
@@ -150,21 +151,26 @@ async def _async_update_data(self) -> LockState:
150151
pass
151152

152153
new_data.auto_lock_seconds = details.autoLockTime
153-
new_data.auto_lock = True if details.autoLockTime > 0 else False
154+
if details.autoLockSeconds > 0:
155+
new_data.auto_lock = True
156+
else:
157+
new_data.auto_lock = False
154158
new_data.lock_sound = details.lockSound == 1
155159

156160
new_data.passage_mode_config = await self.api.get_lock_passage_mode_config(
157161
self.lock_id
158162
)
159-
160-
if Features.door_sensor in Features.from_feature_value(details.featureValue):
163+
164+
if Features.door_sensor in Features.from_feature_value(
165+
details.featureValue
166+
):
161167
sensor = await self.api.get_sensor(self.lock_id)
162168
if sensor.battery_level is not None:
163169
new_data.sensor_battery = sensor.battery_level
164170
new_data.sensor = True
165171
else:
166172
new_data.sensor = False
167-
173+
168174
return new_data
169175
except Exception as err:
170176
raise UpdateFailed(err) from err

custom_components/ttlock/models.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ class State(Enum):
5050
unlocked = 1
5151
unknown = 2
5252

53+
5354
class SensorState(Enum):
5455
"""State of the sensor."""
56+
5557
opened = 0
5658
closed = 1
5759
unknown = None
5860

61+
5962
class Lock(BaseModel):
6063
"""Lock details."""
6164

@@ -82,6 +85,7 @@ class Lock(BaseModel):
8285
# sensitive fields
8386
noKeyPwd: str = Field(alias="adminPwd")
8487

88+
8589
class Sensor(BaseModel):
8690
"""sensor details."""
8791

@@ -90,12 +94,14 @@ class Sensor(BaseModel):
9094
battery_level: int | None = Field(None, alias="electricQuantity")
9195
mac: str = Field(..., alias="mac")
9296

97+
9398
class LockState(BaseModel):
9499
"""Lock state."""
95100

96101
locked: State | None = Field(State.unknown, alias="state")
97102
opened: SensorState | None = Field(SensorState.unknown, alias="sensorState")
98103

104+
99105
class PassageModeConfig(BaseModel):
100106
"""The passage mode configuration of the lock."""
101107

@@ -279,7 +285,7 @@ def state(self) -> LockState:
279285
elif self.success and self.event.action == Action.unlock:
280286
return LockState(state=State.unlocked)
281287
return LockState(state=None)
282-
288+
283289
@property
284290
def sensorState(self) -> LockState:
285291
"""The end state of the sensor after this event."""

custom_components/ttlock/sensor.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ async def async_added_to_hass(self) -> None:
9292

9393
self._attr_native_value = last_state.state
9494

95+
9596
class SensorBattery(BaseLockEntity, SensorEntity):
96-
"""Representaion of sensor bettery."""
97+
"""Representation of sensor battery."""
9798

9899
_attr_device_class = SensorDeviceClass.BATTERY
99100
_attr_native_unit_of_measurement = PERCENTAGE
100101

101102
def _update_from_coordinator(self) -> None:
102103
"""Fetch state from the device."""
103104
self._attr_name = f"{self.coordinator.data.name} Sensor Battery"
104-
self._attr_native_value = self.coordinator.data.sensor_battery
105+
self._attr_native_value = self.coordinator.data.sensor_battery

custom_components/ttlock/services.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def register(self) -> None:
9696
{
9797
vol.Required(ATTR_ENTITY_ID): cv.entity_ids,
9898
vol.Required(CONF_ENABLED): cv.boolean,
99-
vol.Optional(CONF_SECONDS): vol.All(vol.Coerce(int), vol.Range(min=0, max=60)),
99+
vol.Optional(CONF_SECONDS): vol.All(
100+
vol.Coerce(int), vol.Range(min=0, max=60)
101+
),
100102
}
101103
),
102104
)
@@ -168,12 +170,14 @@ async def handle_cleanup_passcodes(self, call: ServiceCall) -> ServiceResponse:
168170
removed.append(code.name)
169171

170172
return {"removed": removed}
171-
173+
172174
async def handle_set_autolock(self, call: ServiceCall):
173-
"""Set the autolock seconds"""
175+
"""Set the autolock seconds."""
174176

175177
if call.data.get(CONF_ENABLED):
176-
seconds = call.data.get(CONF_SECONDS) if call.data.get(CONF_SECONDS) > 0 else 10
178+
seconds = (
179+
call.data.get(CONF_SECONDS) if call.data.get(CONF_SECONDS) > 0 else 10
180+
)
177181
else:
178182
seconds = 0
179183

@@ -182,4 +186,3 @@ async def handle_set_autolock(self, call: ServiceCall):
182186
coordinator.data.auto_lock = call.data.get(CONF_ENABLED)
183187
coordinator.data.auto_lock_seconds = seconds
184188
coordinator.async_update_listeners()
185-

custom_components/ttlock/services.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ set_autolock:
125125
integration: ttlock
126126
domain: lock
127127
fields:
128-
enabled:
128+
enabled:
129129
name: Enabled
130130
description: Should the Autolock feature for the lock be enabled?
131131
required: true
@@ -141,5 +141,3 @@ set_autolock:
141141
min: 0
142142
max: 60
143143
unit_of_measurement: secs
144-
145-

custom_components/ttlock/switch.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import logging
65
from typing import Any
76

87
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
@@ -26,14 +25,15 @@ async def async_setup_entry(
2625
entity
2726
for coordinator in lock_coordinators(hass, entry)
2827
for entity in (
29-
Autolock(coordinator),
30-
Locksound(coordinator),
28+
AutoLock(coordinator),
29+
LockSound(coordinator),
3130
)
3231
]
3332
)
3433

34+
3535
class AutoLock(BaseLockEntity, SwitchEntity):
36-
"""The entity object for a switch"""
36+
"""The entity object for a switch."""
3737

3838
_attr_device_class = SwitchDeviceClass.SWITCH
3939

@@ -50,8 +50,9 @@ async def async_turn_off(self, **kwargs: Any) -> None:
5050
"""Turn the entity off."""
5151
await self.coordinator.auto_lock_off()
5252

53+
5354
class LockSound(BaseLockEntity, SwitchEntity):
54-
"""The entity object for a switch"""
55+
"""The entity object for a switch."""
5556

5657
_attr_device_class = SwitchDeviceClass.SWITCH
5758

@@ -67,4 +68,3 @@ async def async_turn_on(self, **kwargs: Any) -> None:
6768
async def async_turn_off(self, **kwargs: Any) -> None:
6869
"""Turn the entity off."""
6970
await self.coordinator.lock_sound_off()
70-

0 commit comments

Comments
 (0)