formatting
This commit is contained in:
@@ -15,9 +15,7 @@ class Door(Hass):
|
|||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
self.app: 'RoomController' = await self.get_app(self.args['app'])
|
self.app: 'RoomController' = await self.get_app(self.args['app'])
|
||||||
self.logger = console.load_rich_config(
|
self.logger = console.load_rich_config(room=self.app.name, component=type(self).__name__)
|
||||||
room=self.app.name, component=type(self).__name__
|
|
||||||
)
|
|
||||||
self.log(f'Connected to AD app [room]{self.app.name}[/]', level='DEBUG')
|
self.log(f'Connected to AD app [room]{self.app.name}[/]', level='DEBUG')
|
||||||
|
|
||||||
await self.listen_state(
|
await self.listen_state(
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ class ApplyKwargs(BaseModel):
|
|||||||
class ControllerStateConfig(BaseModel):
|
class ControllerStateConfig(BaseModel):
|
||||||
time: Optional[str | datetime] = None
|
time: Optional[str | datetime] = None
|
||||||
elevation: Optional[float] = None
|
elevation: Optional[float] = None
|
||||||
direction: Optional[Annotated[SunDirection, BeforeValidator(str_to_direction)]] = (
|
direction: Optional[Annotated[SunDirection, BeforeValidator(str_to_direction)]] = None
|
||||||
None
|
|
||||||
)
|
|
||||||
off_duration: Optional[OffDuration] = None
|
off_duration: Optional[OffDuration] = None
|
||||||
scene: dict[str, State] | str
|
scene: dict[str, State] | str
|
||||||
|
|
||||||
@@ -57,13 +55,9 @@ class ControllerStateConfig(BaseModel):
|
|||||||
def check_args(cls, values):
|
def check_args(cls, values):
|
||||||
time, elevation = values.get('time'), values.get('elevation')
|
time, elevation = values.get('time'), values.get('elevation')
|
||||||
if time is not None and elevation is not None:
|
if time is not None and elevation is not None:
|
||||||
raise PydanticCustomError(
|
raise PydanticCustomError('bad_time_spec', 'Only one of time or elevation can be set.')
|
||||||
'bad_time_spec', 'Only one of time or elevation can be set.'
|
|
||||||
)
|
|
||||||
elif elevation is not None and 'direction' not in values:
|
elif elevation is not None and 'direction' not in values:
|
||||||
raise PydanticCustomError(
|
raise PydanticCustomError('no_sun_dir', 'Needs sun direction with elevation')
|
||||||
'no_sun_dir', 'Needs sun direction with elevation'
|
|
||||||
)
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def to_apply_kwargs(self, **kwargs):
|
def to_apply_kwargs(self, **kwargs):
|
||||||
@@ -85,9 +79,7 @@ class RoomControllerConfig(BaseModel):
|
|||||||
if app_cfg['class'] == 'RoomController':
|
if app_cfg['class'] == 'RoomController':
|
||||||
return cls.model_validate(app_cfg)
|
return cls.model_validate(app_cfg)
|
||||||
|
|
||||||
def __rich_console__(
|
def __rich_console__(self, console: Console, options: ConsoleOptions) -> RenderResult:
|
||||||
self, console: Console, options: ConsoleOptions
|
|
||||||
) -> RenderResult:
|
|
||||||
table = Table(
|
table = Table(
|
||||||
Column('Time', width=15),
|
Column('Time', width=15),
|
||||||
Column('Scene'),
|
Column('Scene'),
|
||||||
|
|||||||
@@ -65,14 +65,11 @@ class Motion(Hass):
|
|||||||
|
|
||||||
if self.state_mismatch:
|
if self.state_mismatch:
|
||||||
self.log(
|
self.log(
|
||||||
f'Sensor is {self.sensor_state} '
|
f'Sensor is {self.sensor_state} ' f'and light is {self.ref_entity_state}',
|
||||||
f'and light is {self.ref_entity_state}',
|
|
||||||
level='WARNING',
|
level='WARNING',
|
||||||
)
|
)
|
||||||
if self.sensor_state:
|
if self.sensor_state:
|
||||||
self.app.activate(
|
self.app.activate(kwargs={'cause': f'Syncing state with {self.sensor.entity_id}'})
|
||||||
kwargs={'cause': f'Syncing state with {self.sensor.entity_id}'}
|
|
||||||
)
|
|
||||||
|
|
||||||
# don't need to await these because they'll already get turned into a task by the utils.sync_wrapper decorator
|
# don't need to await these because they'll already get turned into a task by the utils.sync_wrapper decorator
|
||||||
self.listen_state(
|
self.listen_state(
|
||||||
@@ -107,9 +104,7 @@ class Motion(Hass):
|
|||||||
oneshot=True,
|
oneshot=True,
|
||||||
cause='motion on',
|
cause='motion on',
|
||||||
)
|
)
|
||||||
self.log(
|
self.log(f'Waiting for sensor motion on [friendly_name]{self.sensor.friendly_name}[/]')
|
||||||
f'Waiting for sensor motion on [friendly_name]{self.sensor.friendly_name}[/]'
|
|
||||||
)
|
|
||||||
if self.sensor_state:
|
if self.sensor_state:
|
||||||
self.log(
|
self.log(
|
||||||
f'Sensor [friendly_name]{self.sensor.friendly_name}[/] is already on',
|
f'Sensor [friendly_name]{self.sensor.friendly_name}[/] is already on',
|
||||||
@@ -137,18 +132,14 @@ class Motion(Hass):
|
|||||||
level='WARNING',
|
level='WARNING',
|
||||||
)
|
)
|
||||||
|
|
||||||
def callback_light_on(
|
def callback_light_on(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
self, entity=None, attribute=None, old=None, new=None, kwargs=None
|
|
||||||
):
|
|
||||||
"""Called when the light turns on"""
|
"""Called when the light turns on"""
|
||||||
if new is not None:
|
if new is not None:
|
||||||
self.log(f'Detected {entity} turning on', level='DEBUG')
|
self.log(f'Detected {entity} turning on', level='DEBUG')
|
||||||
duration = self.app.off_duration()
|
duration = self.app.off_duration()
|
||||||
self.listen_motion_off(duration)
|
self.listen_motion_off(duration)
|
||||||
|
|
||||||
def callback_light_off(
|
def callback_light_off(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
self, entity=None, attribute=None, old=None, new=None, kwargs=None
|
|
||||||
):
|
|
||||||
"""Called when the light turns off"""
|
"""Called when the light turns off"""
|
||||||
self.log(f'Detected {entity} turning off', level='DEBUG')
|
self.log(f'Detected {entity} turning off', level='DEBUG')
|
||||||
self.listen_motion_on()
|
self.listen_motion_on()
|
||||||
|
|||||||
@@ -200,9 +200,7 @@ class RoomController(Hass, Mqtt):
|
|||||||
|
|
||||||
elif isinstance(scene_kwargs, dict):
|
elif isinstance(scene_kwargs, dict):
|
||||||
self.call_service('scene/apply', **scene_kwargs)
|
self.call_service('scene/apply', **scene_kwargs)
|
||||||
self.log(
|
self.log(f'Applied scene:\n{json.dumps(scene_kwargs, indent=2)}', level='DEBUG')
|
||||||
f'Applied scene:\n{json.dumps(scene_kwargs, indent=2)}', level='DEBUG'
|
|
||||||
)
|
|
||||||
|
|
||||||
elif scene_kwargs is None:
|
elif scene_kwargs is None:
|
||||||
self.log('No scene, ignoring...')
|
self.log('No scene, ignoring...')
|
||||||
|
|||||||
Reference in New Issue
Block a user