예제 #1
0
파일: scene.py 프로젝트: spacegaier/xknx
class Scene(Device):
    """Class for managing a scene."""
    def __init__(
        self,
        xknx: "XKNX",
        name: str,
        group_address: Optional["GroupAddressableType"] = None,
        scene_number: int = 1,
        device_updated_cb: Optional[DeviceCallbackType] = None,
    ):
        """Initialize Sceneclass."""
        # pylint: disable=too-many-arguments
        super().__init__(xknx, name, device_updated_cb)

        # TODO: state_updater: disable for scene number per default?
        self.scene_value = RemoteValueSceneNumber(
            xknx,
            group_address=group_address,
            device_name=self.name,
            feature_name="Scene number",
            after_update_cb=self.after_update,
        )
        self.scene_number = int(scene_number)

    def _iter_remote_values(self) -> Iterator[RemoteValueSceneNumber]:
        """Iterate the devices RemoteValue classes."""
        yield self.scene_value

    @classmethod
    def from_config(cls, xknx: "XKNX", name: str, config: Any) -> "Scene":
        """Initialize object from configuration structure."""
        group_address = config.get("group_address")
        scene_number = int(config.get("scene_number"))
        return cls(xknx,
                   name=name,
                   group_address=group_address,
                   scene_number=scene_number)

    def __str__(self) -> str:
        """Return object as readable string."""
        return '<Scene name="{}" ' 'scene_value="{}" scene_number="{}" />'.format(
            self.name, self.scene_value.group_addr_str(), self.scene_number)

    async def run(self) -> None:
        """Activate scene."""
        await self.scene_value.set(self.scene_number)

    async def do(self, action: str) -> None:
        """Execute 'do' commands."""
        if action == "run":
            await self.run()
        else:
            logger.warning("Could not understand action %s for device %s",
                           action, self.get_name())
예제 #2
0
파일: scene.py 프로젝트: stefan-knx/xknx
class Scene(Device):
    """Class for managing a scene."""
    def __init__(
        self,
        xknx: XKNX,
        name: str,
        group_address: GroupAddressesType | None = None,
        scene_number: int = 1,
        device_updated_cb: DeviceCallbackType | None = None,
    ):
        """Initialize Sceneclass."""
        super().__init__(xknx, name, device_updated_cb)

        # TODO: state_updater: disable for scene number per default?
        self.scene_value = RemoteValueSceneNumber(
            xknx,
            group_address=group_address,
            device_name=self.name,
            feature_name="Scene number",
            after_update_cb=self.after_update,
        )
        self.scene_number = int(scene_number)

    def _iter_remote_values(self) -> Iterator[RemoteValueSceneNumber]:
        """Iterate the devices RemoteValue classes."""
        yield self.scene_value

    @property
    def unique_id(self) -> str | None:
        """Return unique id for this device."""
        return f"{self.scene_value.group_address}_{self.scene_number}"

    def __str__(self) -> str:
        """Return object as readable string."""
        return '<Scene name="{}" ' 'scene_value={} scene_number="{}" />'.format(
            self.name, self.scene_value.group_addr_str(), self.scene_number)

    async def run(self) -> None:
        """Activate scene."""
        await self.scene_value.set(self.scene_number)
예제 #3
0
class Scene(Device):
    """Class for managing a scene."""

    def __init__(self,
                 xknx,
                 name,
                 group_address=None,
                 scene_number=1,
                 device_updated_cb=None):
        """Initialize Sceneclass."""
        # pylint: disable=too-many-arguments
        super().__init__(xknx, name, device_updated_cb)

        self.scene_value = RemoteValueSceneNumber(
            xknx,
            group_address,
            device_name=self.name,
            after_update_cb=self.after_update)
        self.scene_number = int(scene_number)

    @classmethod
    def from_config(cls, xknx, name, config):
        """Initialize object from configuration structure."""
        group_address = \
            config.get('group_address')
        scene_number = \
            int(config.get('scene_number'))
        return cls(
            xknx,
            name=name,
            group_address=group_address,
            scene_number=scene_number)

    def has_group_address(self, group_address):
        """Test if device has given group address."""
        return self.scene_value.has_group_address(group_address)

    def __str__(self):
        """Return object as readable string."""
        return '<Scene name="{0}" ' \
               'scene_value="{1}" scene_number="{2}" />' \
            .format(
                self.name,
                self.scene_value.group_addr_str(),
                self.scene_number)

    async def run(self):
        """Activate scene."""
        await self.scene_value.set(self.scene_number)

    async def do(self, action):
        """Execute 'do' commands."""
        if action == "run":
            await self.run()
        else:
            self.xknx.logger.warning("Could not understand action %s for device %s", action, self.get_name())

    def state_addresses(self):
        """Return group addresses which should be requested to sync state."""
        return []

    def __eq__(self, other):
        """Equal operator."""
        return self.__dict__ == other.__dict__