from __future__ import annotations
import logging
from abc import ABCMeta
from typing import Any
from pyobs.interfaces import FitsHeaderEntry, IFitsHeaderBefore, IReady, IRoof, ReadyState
from pyobs.mixins import MotionStatusMixin, WeatherAwareMixin
from pyobs.modules import Module
from pyobs.utils.enums import MotionStatus
log = logging.getLogger(__name__)
class BaseRoof(WeatherAwareMixin, MotionStatusMixin, IRoof, IFitsHeaderBefore, Module, metaclass=ABCMeta):
"""Base class for roofs."""
__module__ = "pyobs.modules.roof"
def __init__(self, **kwargs: Any):
"""Initialize a new base roof."""
Module.__init__(self, **kwargs)
WeatherAwareMixin.__init__(self, **kwargs)
MotionStatusMixin.__init__(self, **kwargs)
[docs]
async def open(self) -> None:
"""Open module."""
await Module.open(self)
# open mixins
await WeatherAwareMixin.open(self)
await MotionStatusMixin.open(self)
# publish initial ready state
await self.comm.set_state(IReady, ReadyState(ready=self._is_ready()))
def _is_ready(self) -> bool:
"""The roof is ready if it is open (not parked, initializing, parking, error, or unknown)."""
return self.motion_status() not in [
MotionStatus.PARKED,
MotionStatus.INITIALIZING,
MotionStatus.PARKING,
MotionStatus.ERROR,
MotionStatus.UNKNOWN,
]
__all__ = ["BaseRoof"]