-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restart development from scratch with better development plan and str…
…ucture.
- Loading branch information
Showing
14 changed files
with
667 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Home Assistant Integration Development CursorRules | ||
|
||
# General Python Best Practices | ||
- Use type annotations for all functions and methods. | ||
- Follow PEP 8 for code style and formatting. | ||
- Use docstrings to document all public classes and methods. | ||
- Prefer list comprehensions and generator expressions for creating lists and iterators. | ||
|
||
# Home Assistant Specific Guidelines | ||
- Ensure all integrations are structured according to the Home Assistant architecture. | ||
- Use the `hass` object for accessing core Home Assistant functionalities. | ||
- Define entities using the `Entity` class or its derivatives. | ||
- Implement config entries for user configuration. | ||
- Use the `async` keyword for I/O-bound operations to ensure non-blocking behavior. | ||
- Follow the Integration Quality Scale to ensure high-quality integrations. | ||
|
||
# Code Structure | ||
- Organize code into modules: `__init__.py`, `sensor.py`, `binary_sensor.py`, etc. | ||
- Use constants for configuration keys and default values. | ||
- Separate logic into helper functions or classes to improve readability and maintainability. | ||
|
||
# Error Handling | ||
- Use Python's built-in exceptions for error handling. | ||
- Log errors and warnings using Home Assistant's logging framework. | ||
|
||
# Testing | ||
- Write unit tests for all new features and bug fixes. | ||
- Use Home Assistant's test utilities for setting up test environments. | ||
|
||
# Documentation | ||
- Provide clear and concise documentation for the integration. | ||
- Include examples of configuration and usage in the README.md file. | ||
|
||
# Contribution Guidelines | ||
- Ensure all contributions are original or properly credited. | ||
- Follow the repository's contribution guidelines for pull requests. | ||
|
||
# Feature Scope and Requirements | ||
- Implement only the features that are explicitly requested or required. | ||
- Avoid adding unnecessary features that could complicate the integration. | ||
- Prioritize maintaining simplicity and clarity in the codebase. | ||
|
||
# Beginner-Friendly Guidelines | ||
- Provide clear explanations and comments for all code outputs. | ||
- Document the purpose and usage of each function and class. | ||
- Use simple and straightforward methods whenever possible. | ||
- Avoid complex patterns unless absolutely necessary, and explain them thoroughly if used. | ||
|
||
# Entity-Specific Guidelines | ||
- Use the most appropriate class, service, method, or action for the entity type in question. | ||
- Ensure that the entity's functionality aligns with Home Assistant's core capabilities and standards. | ||
- Regularly review Home Assistant's documentation for updates on best practices and new features. | ||
|
||
# Additional Resources | ||
- Refer to the Home Assistant developer documentation for detailed guidelines: https://developers.home-assistant.io/docs/development_index/ \ | ||
- Refer to 'dev_plan.md' for the overarching project plan | ||
- Refer to 'instruction_set.md' for project specific instructions. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,60 @@ | ||
"""The StockPile integration.""" | ||
from homeassistant.core import HomeAssistant, ServiceCall | ||
from homeassistant.config_entries import ConfigEntry | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Any | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.const import Platform | ||
from homeassistant.helpers.reload import async_setup_reload_service | ||
from homeassistant.core import HomeAssistant | ||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.helpers.typing import ConfigType | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
# Define the schema for each stockpile entry | ||
STOCKPILE_SCHEMA = vol.Schema({ | ||
vol.Required("name"): cv.string, | ||
vol.Required("unit"): cv.string, | ||
vol.Required("initial_quantity"): cv.positive_float, | ||
vol.Optional("min_quantity", default=0): cv.positive_float, | ||
vol.Optional("max_quantity"): cv.positive_float, | ||
vol.Optional("step_size", default=1): cv.positive_float, | ||
}) | ||
|
||
# Define the main configuration schema | ||
CONFIG_SCHEMA = vol.Schema({ | ||
vol.Required("stockpile"): vol.Schema({ | ||
vol.Required("piles"): vol.All( | ||
cv.ensure_list, | ||
[STOCKPILE_SCHEMA] | ||
) | ||
}) | ||
}, extra=vol.ALLOW_EXTRA) | ||
|
||
from .const import DOMAIN | ||
PLATFORMS = [Platform.SENSOR, Platform.CALENDAR] | ||
|
||
PLATFORMS = [Platform.NUMBER] | ||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: | ||
"""Set up the StockPile integration.""" | ||
if "stockpile" not in config: | ||
return True | ||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Set up StockPile from a config entry.""" | ||
hass.data.setdefault(DOMAIN, {}) | ||
hass.data[DOMAIN][entry.entry_id] = entry.data | ||
# Store the configuration in hass.data | ||
hass.data["stockpile"] = {} | ||
conf = config["stockpile"] | ||
|
||
# Add reload service | ||
await async_setup_reload_service(hass, DOMAIN, PLATFORMS) | ||
# Set up each stockpile | ||
for pile in conf["piles"]: | ||
pile_name = pile["name"] | ||
hass.data["stockpile"][pile_name] = pile | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
return True | ||
# Forward the setup to the sensor and calendar platforms | ||
for platform in PLATFORMS: | ||
hass.async_create_task( | ||
hass.helpers.discovery.async_load_platform( | ||
platform, "stockpile", conf, config | ||
) | ||
) | ||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
if unload_ok: | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
return unload_ok | ||
return True |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
"""Constants for StockPile.""" | ||
"""Constants for the StockPile integration.""" | ||
DOMAIN = "stockpile" | ||
MANUFACTURER = "StockPile" | ||
|
||
# Entity naming patterns | ||
PILE_SENSOR_NAME = "pile_{}" | ||
STOCK_SENSOR_NAME = "stock_{}" | ||
CALENDAR_NAME = "pile_{}" | ||
|
||
# Attributes | ||
ATTR_UNIT = "unit" | ||
ATTR_MIN_QUANTITY = "min_quantity" | ||
ATTR_MAX_QUANTITY = "max_quantity" | ||
ATTR_STEP_SIZE = "step_size" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"domain": "stockpile", | ||
"name": "StockPile", | ||
"version": "1.0.1", | ||
"documentation": "https://github.com/jack3308/stockpile", | ||
"documentation": "https://github.com/username/ha-stockpile", | ||
"dependencies": [], | ||
"codeowners": ["@jack3308"], | ||
"config_flow": true, | ||
"iot_class": "local_push" | ||
"codeowners": [], | ||
"requirements": [], | ||
"version": "0.1.0", | ||
"iot_class": "calculated" | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.