Initial commit of Simple Home Assistant Addon with web interface
This commit is contained in:
21
homeassistant-addon/Dockerfile
Normal file
21
homeassistant-addon/Dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
FROM homeassistant/amd64-base:latest
|
||||
|
||||
# Install basic dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
python3-pip \
|
||||
python3-dev \
|
||||
build-essential \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy addon files
|
||||
COPY requirements.txt /
|
||||
COPY run.sh /
|
||||
COPY config.yaml /
|
||||
|
||||
# Set permissions
|
||||
RUN chmod +x /run.sh
|
||||
|
||||
# Start the addon
|
||||
CMD ["/run.sh"]
|
||||
16
homeassistant-addon/README.md
Normal file
16
homeassistant-addon/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Simple Home Assistant Addon
|
||||
|
||||
A basic Home Assistant addon template.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download this addon from the Home Assistant Addon Store
|
||||
2. Install it through the Home Assistant Supervisor interface
|
||||
|
||||
## Configuration
|
||||
|
||||
No configuration is required for this basic addon.
|
||||
|
||||
## Usage
|
||||
|
||||
This addon provides a simple example of how to create a Home Assistant addon.
|
||||
42
homeassistant-addon/main.py
Normal file
42
homeassistant-addon/main.py
Normal file
@ -0,0 +1,42 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
import aiohttp
|
||||
import yaml
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
handlers=[
|
||||
logging.StreamHandler(sys.stdout)
|
||||
]
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def main():
|
||||
_LOGGER.info("Starting Simple Addon")
|
||||
|
||||
# Example of Home Assistant API usage
|
||||
async with aiohttp.ClientSession() as session:
|
||||
try:
|
||||
# Get Home Assistant info
|
||||
async with session.get('http://supervisor/core/info') as response:
|
||||
if response.status == 200:
|
||||
data = await response.json()
|
||||
_LOGGER.info(f"Home Assistant version: {data.get('version')}")
|
||||
except Exception as e:
|
||||
_LOGGER.error(f"Error connecting to Home Assistant: {str(e)}")
|
||||
|
||||
# Keep the addon running
|
||||
while True:
|
||||
await asyncio.sleep(60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except KeyboardInterrupt:
|
||||
_LOGGER.info("Addon stopped")
|
||||
4
homeassistant-addon/requirements.txt
Normal file
4
homeassistant-addon/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
requests==2.31.0
|
||||
aiohttp==3.8.5
|
||||
asyncio==3.4.3
|
||||
pyyaml==6.0.1
|
||||
8
homeassistant-addon/run.sh
Normal file
8
homeassistant-addon/run.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set environment variables
|
||||
export PYTHONPATH=/usr/local/lib/python3.9/site-packages
|
||||
|
||||
# Start the addon
|
||||
python3 -m pip install -r /requirements.txt
|
||||
python3 /app/main.py
|
||||
Reference in New Issue
Block a user