Metadata-Version: 2.1
Name: sectoralarm
Version: 1.1.0
Summary: A Python library for interacting with the Sector Alarm API.
Home-page: https://github.com/garnser/sector_alarm
Author: Jonathan Petersson
Author-email: jpetersson@garnser.se
Project-URL: Bug Tracker, https://github.com/garnser/sector_alarm/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: requests

# Sector Alarm API Data Retrieval Script

This Python script authenticates with the Sector Alarm API and retrieves various sensor data, including temperature, humidity, doors and windows status, smoke detectors, and leakage detectors. The results are consolidated and output as a JSON object.

## Prerequisites

- **Python 3.6+**: Make sure Python is installed on your system.
- **Environment Variables**: Set the following environment variables:
  - `SA_EMAIL`: Your Sector Alarm account email.
  - `SA_PASSWORD`: Your Sector Alarm account password.
  - `SA_PANELID`: The ID of the panel you wish to retrieve data from.

### Dependencies

Install the required dependencies using `pip`:

```bash
pip install requests
```

## Configuration
The script relies on the following environment variables for authentication and panel identification:

- `SA_EMAIL`: Sector Alarm account email.
- `SA_PASSWORD`: Sector Alarm account password.
- `SA_PANELID`: Sector Alarm panel ID.
You can set these in your shell session:

```bash
export SA_EMAIL="your_email@example.com"
export SA_PASSWORD="your_password"
export SA_PANELID="your_panel_id"
```

Alternatively, you can create a .env file and load it before running the script.

## Usage
Run the script as follows:

```bash
python sector_alarm.py
```

Upon successful authentication, the script will attempt to retrieve data from multiple endpoints and output it in JSON format.

## Script Structure
- `login()`: Authenticates with the Sector Alarm API and retrieves an authorization token.
- `try_panel_endpoints()`: Fetches data from various /api/panel endpoints, including `GetPanelStatus`, `GetSmartplugStatus`, `GetLockStatus` and `GetLogs`.
- `try_housecheck_endpoints()`: Fetches data from various `/api/housecheck` and `/api/v2/housecheck` endpoints, including:
- `Humidity`: Retrieves humidity levels.
- `Doors and Windows`: Retrieves the status of doors and windows.
- `Leakage Detectors`: Retrieves data on any leakage detectors.
- `Smoke Detectors`: Retrieves smoke detector statuses.
- `Cameras`: Retrieves camera statuses.
- `Persons`: Retrieves person information.
- `Temperatures`: Retrieves temperature levels.
`get_consolidated_data()`: Combines all retrieved data and outputs it as a JSON-formatted string.

### Example Output
After running the script, you should see JSON output similar to the following:

```json
{
    "Humidity": [
        {"Label": "Laundry Room", "Humidity": "45%"}
    ],
    "Doors and Windows": [
        {"Label": "Front Door", "Status": "Closed"},
        {"Label": "Back Door", "Status": "Open"}
    ],
    "Smoke Detectors": [
        {"Label": "Hallway", "Status": "No Smoke Detected"}
    ]
}
```

## Logging
The script uses Python’s `logging` module to log success or error messages for each endpoint call. Adjust the logging level if needed.

## Troubleshooting
- **Invalid Credentials**: Ensure that your `SA_EMAIL` and `SA_PASSWORD` values are correct.
- **API Version Issues**: The script is set to use `API-Version: 5`, which may need updating if the API changes.
- **Endpoint Failures**: If specific endpoints fail, confirm they are available and your panel supports them.

## License
This script is for personal and educational use. Please ensure you have permission to access the Sector Alarm API.
