jeedomdaemon


Namejeedomdaemon JSON
Version 0.10.0 PyPI version JSON
download
home_pagehttps://github.com/Mips2648/jeedom-daemon-py
SummaryA base to implement Jeedom daemon in python
upload_time2024-06-24 11:50:26
maintainerNone
docs_urlNone
authorMips
requires_pythonNone
licenseMIT
keywords jeedom daemon asyncio
VCS
bugtrack_url
requirements aiohttp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jeedom-daemon-py

![pytest 3.9](https://github.com/Mips2648/jeedom-daemon-py/actions/workflows/pytest-3.9.yml/badge.svg)

![pytest 3.11](https://github.com/Mips2648/jeedom-daemon-py/actions/workflows/pytest-3.11.yml/badge.svg)

## Description

This library provide everything needed to build a daemon for a plugin for Jeedom in python.
It's possible to get a daemon skeleton by typing literally less than 5 lines of code.

## Requirements

* **Python 3.9+**

## How to install

Make sure to add it in your requirements

### Manually

```bash
pip3 install jeedomdaemon
```

### Via Jeedom core packages.json

```json
{
  "pre-install": {},
  "apt": {
    "python3-pip": {}
  },
  "pip3": {
    "jeedomdaemon": {}
  },
  "npm": {},
  "yarn": {},
  "plugin": {},
  "post-install": {}
}
```

### Via requirements.txt

```txt
jeedomdaemon~=0.9.7
```

## Quick start

Create a file `myDaemon.py` and copy/past the 4 lines of code below and that's it, nothing else to do, your daemon is good to start:

```python
from jeedomdaemon.base_daemon import BaseDaemon

class MyDaemon(BaseDaemon):
    pass

MyDaemon().run()
```

Of course, this does nothing so far except starting, accepting incoming requests from your php code and stopping when it is needed.

So let's add few lines in your daemon class:

```python
from jeedomdaemon.base_daemon import BaseDaemon

class MyDaemon(BaseDaemon):
    def __init__(self) -> None:
        # Standard initialisation
        super().__init__(on_start_cb=self.on_start, on_message_cb=self.on_message, on_stop_cb=self.on_stop)

        # Add here any initialisation your daemon would need

    async def on_start(self):
        """
        This method will be called when your daemon start.
        This is the place where you should create yours tasks, login to remote system, etc
        """
        # if you don't have specific action to do on start, do not create this method
        pass


    async def on_message(self, message: list):
        """
        This function will be called once a message is received from Jeedom; check on api key is done already, just care about your logic
        You must implement the different actions that your daemon can handle.
        """
        pass

    async def on_stop(self):
        """
        This callback will be called when daemon need to stop`
        You need to close your remote connexions and cancel background tasks if any here.
        """
        # if you don't have specific action to do on stop, do not create this method
        pass

MyDaemon().run()
```

## Configuration

Without additional work, your daemon will accept following argument when started by your php code:

* --loglevel - a string (Jeedom format) giving the log Level for the daemon
* --sockethost - usually not needed, default is '127.0.0.1'
* --socketport - port on which the daemon will open a tcp socket to listen for incomming message from your php code
* --callback - callback url to use by your daemon to send data to your php code
* --apikey - the apikey use to valid communication
* --pid - the pid filename
* --cycle - a float value giving at which frequency daemon should send request to your PHP code, by default every 0.5s (max)

It will happen that you need to receive some additional values from Jeedom to be able to start your daemon, like a user & password to login somewhere. In that case create a child class like in this example and provide it during daemon initialisation:

```python
from jeedomdaemon.base_daemon import BaseDaemon
from jeedomdaemon.base_config import BaseConfig

class DemoConfig(BaseConfig):
    """This is where you declare your custom argument/configuration

    Remember that all usual arguments are managed by the BaseConfig class already so you only have to take care of yours; e.g. user & password in this case
    """
    def __init__(self):
        super().__init__()

        self.add_argument("--user", type=str, default='Harrison')
        self.add_argument("--password", type=str)

class MyDaemon(BaseDaemon):
    def __init__(self) -> None:
        # provide your custom config class during init
        super().__init__(config=DemoConfig(), on_start_cb=...)

        # ...

```

## What's next

I suggest you to take a look at this [demo plugin](https://github.com/Mips2648/jeedom-aiodemo) which implement this library

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Mips2648/jeedom-daemon-py",
    "name": "jeedomdaemon",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "JEEDOM, DAEMON, ASYNCIO",
    "author": "Mips",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/25/6b/7893e18e7ab54208a8a3fff99f279bf81c1ba2944f459202da5bac31830a/jeedomdaemon-0.10.0.tar.gz",
    "platform": null,
    "description": "# jeedom-daemon-py\n\n![pytest 3.9](https://github.com/Mips2648/jeedom-daemon-py/actions/workflows/pytest-3.9.yml/badge.svg)\n\n![pytest 3.11](https://github.com/Mips2648/jeedom-daemon-py/actions/workflows/pytest-3.11.yml/badge.svg)\n\n## Description\n\nThis library provide everything needed to build a daemon for a plugin for Jeedom in python.\nIt's possible to get a daemon skeleton by typing literally less than 5 lines of code.\n\n## Requirements\n\n* **Python 3.9+**\n\n## How to install\n\nMake sure to add it in your requirements\n\n### Manually\n\n```bash\npip3 install jeedomdaemon\n```\n\n### Via Jeedom core packages.json\n\n```json\n{\n  \"pre-install\": {},\n  \"apt\": {\n    \"python3-pip\": {}\n  },\n  \"pip3\": {\n    \"jeedomdaemon\": {}\n  },\n  \"npm\": {},\n  \"yarn\": {},\n  \"plugin\": {},\n  \"post-install\": {}\n}\n```\n\n### Via requirements.txt\n\n```txt\njeedomdaemon~=0.9.7\n```\n\n## Quick start\n\nCreate a file `myDaemon.py` and copy/past the 4 lines of code below and that's it, nothing else to do, your daemon is good to start:\n\n```python\nfrom jeedomdaemon.base_daemon import BaseDaemon\n\nclass MyDaemon(BaseDaemon):\n    pass\n\nMyDaemon().run()\n```\n\nOf course, this does nothing so far except starting, accepting incoming requests from your php code and stopping when it is needed.\n\nSo let's add few lines in your daemon class:\n\n```python\nfrom jeedomdaemon.base_daemon import BaseDaemon\n\nclass MyDaemon(BaseDaemon):\n    def __init__(self) -> None:\n        # Standard initialisation\n        super().__init__(on_start_cb=self.on_start, on_message_cb=self.on_message, on_stop_cb=self.on_stop)\n\n        # Add here any initialisation your daemon would need\n\n    async def on_start(self):\n        \"\"\"\n        This method will be called when your daemon start.\n        This is the place where you should create yours tasks, login to remote system, etc\n        \"\"\"\n        # if you don't have specific action to do on start, do not create this method\n        pass\n\n\n    async def on_message(self, message: list):\n        \"\"\"\n        This function will be called once a message is received from Jeedom; check on api key is done already, just care about your logic\n        You must implement the different actions that your daemon can handle.\n        \"\"\"\n        pass\n\n    async def on_stop(self):\n        \"\"\"\n        This callback will be called when daemon need to stop`\n        You need to close your remote connexions and cancel background tasks if any here.\n        \"\"\"\n        # if you don't have specific action to do on stop, do not create this method\n        pass\n\nMyDaemon().run()\n```\n\n## Configuration\n\nWithout additional work, your daemon will accept following argument when started by your php code:\n\n* --loglevel - a string (Jeedom format) giving the log Level for the daemon\n* --sockethost - usually not needed, default is '127.0.0.1'\n* --socketport - port on which the daemon will open a tcp socket to listen for incomming message from your php code\n* --callback - callback url to use by your daemon to send data to your php code\n* --apikey - the apikey use to valid communication\n* --pid - the pid filename\n* --cycle - a float value giving at which frequency daemon should send request to your PHP code, by default every 0.5s (max)\n\nIt will happen that you need to receive some additional values from Jeedom to be able to start your daemon, like a user & password to login somewhere. In that case create a child class like in this example and provide it during daemon initialisation:\n\n```python\nfrom jeedomdaemon.base_daemon import BaseDaemon\nfrom jeedomdaemon.base_config import BaseConfig\n\nclass DemoConfig(BaseConfig):\n    \"\"\"This is where you declare your custom argument/configuration\n\n    Remember that all usual arguments are managed by the BaseConfig class already so you only have to take care of yours; e.g. user & password in this case\n    \"\"\"\n    def __init__(self):\n        super().__init__()\n\n        self.add_argument(\"--user\", type=str, default='Harrison')\n        self.add_argument(\"--password\", type=str)\n\nclass MyDaemon(BaseDaemon):\n    def __init__(self) -> None:\n        # provide your custom config class during init\n        super().__init__(config=DemoConfig(), on_start_cb=...)\n\n        # ...\n\n```\n\n## What's next\n\nI suggest you to take a look at this [demo plugin](https://github.com/Mips2648/jeedom-aiodemo) which implement this library\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A base to implement Jeedom daemon in python",
    "version": "0.10.0",
    "project_urls": {
        "Homepage": "https://github.com/Mips2648/jeedom-daemon-py"
    },
    "split_keywords": [
        "jeedom",
        " daemon",
        " asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cb354a96e6453b12f1037fa00f428a4bf3986dc9869ab10db3fae6151316f1d8",
                "md5": "68f87d595a2b018b7823b402c5a24fb1",
                "sha256": "7709cd060ab4794bc23bfcc08f6788e7b30a00ffaea7dc61a2ae2e97ba7172b6"
            },
            "downloads": -1,
            "filename": "jeedomdaemon-0.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "68f87d595a2b018b7823b402c5a24fb1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12078,
            "upload_time": "2024-06-24T11:50:24",
            "upload_time_iso_8601": "2024-06-24T11:50:24.797784Z",
            "url": "https://files.pythonhosted.org/packages/cb/35/4a96e6453b12f1037fa00f428a4bf3986dc9869ab10db3fae6151316f1d8/jeedomdaemon-0.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "256b7893e18e7ab54208a8a3fff99f279bf81c1ba2944f459202da5bac31830a",
                "md5": "0e55135c8f4fde9fdfbf4a32bdc7421a",
                "sha256": "66fe1715f5deac8bae7f54021612eff82d398ad04bbe6883d3c23d9fb313fad1"
            },
            "downloads": -1,
            "filename": "jeedomdaemon-0.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e55135c8f4fde9fdfbf4a32bdc7421a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11432,
            "upload_time": "2024-06-24T11:50:26",
            "upload_time_iso_8601": "2024-06-24T11:50:26.425437Z",
            "url": "https://files.pythonhosted.org/packages/25/6b/7893e18e7ab54208a8a3fff99f279bf81c1ba2944f459202da5bac31830a/jeedomdaemon-0.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-24 11:50:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Mips2648",
    "github_project": "jeedom-daemon-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    "~=",
                    "3.9.5"
                ]
            ]
        }
    ],
    "lcname": "jeedomdaemon"
}
        
Elapsed time: 0.28151s