-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5021db9
Showing
20 changed files
with
2,027 additions
and
0 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,13 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# VSCode | ||
.vscode | ||
|
||
#Resources | ||
resources/*.psd | ||
|
||
#Some Files Used only in DEV | ||
*_dev.py |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Soloam | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,43 @@ | ||
# FireflyIII Integration | ||
|
||
_Component to integrate with [FireflyIII][fireflyiii] chargers._ | ||
|
||
[fireflyiii]: https://www.firefly-iii.org/ | ||
|
||
**This component will set up the following platforms.** | ||
|
||
| Platform | Description | | ||
| ---------- | --------------------------------- | | ||
| `sensor` | Show info from an FireflyIII API. | | ||
| `calendar` | Calendar for invoices | | ||
|
||
## Installation via HACS (recommended) | ||
|
||
[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=firstof9&repository=fireflyiii) | ||
|
||
1. Follow the link [here](https://hacs.xyz/docs/faq/custom_repositories/) | ||
2. Use the custom repo link https://github.com/soloam/ha-fireflyiii-integration | ||
3. Select the category type `integration` | ||
4. Then once it's there (still in HACS) click the INSTALL button | ||
5. Restart Home Assistant | ||
6. Once restarted, in the HA UI go to `Configuration` (the ⚙️ in the lower left) -> `Devices and Services` click `+ Add Integration` and search for `fireflyiii` | ||
|
||
## Manual (non-HACS) | ||
|
||
<details> | ||
<summary>Instructions</summary> | ||
|
||
<br> | ||
You probably do not want to do this! Use the HACS method above unless you know what you are doing and have a good reason as to why you are installing manually | ||
<br> | ||
|
||
1. Using the tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`). | ||
2. If you do not have a `custom_components` directory (folder) there, you need to create it. | ||
3. In the `custom_components` directory (folder) create a new folder called `fireflyiii_integration`. | ||
4. Download _all_ the files from the `custom_components/fireflyiii_integration/` directory (folder) in this repository. | ||
5. Place the files you downloaded in the new directory (folder) you created. | ||
6. Restart Home Assistant | ||
7. Once restarted, in the HA UI go to `Configuration` (the ⚙️ in the lower left) -> `Devices and Services` click `+ Add Integration` and search for `fireflyiii` | ||
</details> | ||
|
||
## Configuration is done in the UI |
Empty file.
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,77 @@ | ||
"""FireflyIII Integration Component.""" | ||
|
||
import logging | ||
|
||
from homeassistant import config_entries, core | ||
from homeassistant.const import CONF_NAME, CONF_URL, Platform | ||
from homeassistant.helpers import device_registry | ||
|
||
from .const import COORDINATOR, DATA, DOMAIN, MANUFACTURER | ||
from .integrations.fireflyiii_coordinator import FireflyiiiCoordinator | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
PLATFORMS = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.CALENDAR] | ||
|
||
|
||
async def async_setup_entry( | ||
hass: core.HomeAssistant, entry: config_entries.ConfigEntry | ||
) -> bool: | ||
"""Set up platform from a ConfigEntry.""" | ||
hass.data.setdefault(DOMAIN, {}) | ||
hass_data = dict(entry.data) | ||
|
||
interval = 60 | ||
|
||
# Update coordinator | ||
coordinator = FireflyiiiCoordinator(hass, interval, entry) | ||
|
||
hass.data[DOMAIN][entry.entry_id] = {DATA: hass_data, COORDINATOR: coordinator} | ||
|
||
# Fetch Initial Data | ||
await coordinator.async_refresh() | ||
|
||
device = device_registry.async_get(hass) | ||
device.async_get_or_create( | ||
config_entry_id=entry.entry_id, | ||
connections={(DOMAIN, entry.entry_id)}, | ||
identifiers={(DOMAIN, entry.entry_id)}, | ||
name=entry.data.get(CONF_NAME), | ||
manufacturer=MANUFACTURER, | ||
model=coordinator.api_data.get("about", {}).get("os", ""), | ||
sw_version=coordinator.api_data.get("about", {}).get("version", ""), | ||
configuration_url=entry.data.get(CONF_URL, ""), | ||
) | ||
|
||
# Forward the setup to the sensor platform. | ||
for platform in PLATFORMS: | ||
hass.async_create_task( | ||
hass.config_entries.async_forward_entry_setup(entry, platform) | ||
) | ||
return True | ||
|
||
|
||
async def options_update_listener( | ||
hass: core.HomeAssistant, entry: config_entries.ConfigEntry | ||
): | ||
"""Handle options update.""" | ||
await hass.config_entries.async_reload(entry.entry_id) | ||
|
||
|
||
async def async_unload_entry( | ||
hass: core.HomeAssistant, entry: config_entries.ConfigEntry | ||
) -> bool: | ||
"""Unload a config entry.""" | ||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): | ||
# Remove config entry from domain. | ||
|
||
# pylint: disable=unused-variable | ||
entry_data = hass.data[DOMAIN].pop(entry.entry_id) | ||
|
||
return unload_ok | ||
|
||
|
||
# pylint: disable=unused-argument | ||
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool: | ||
"""Disallow configuration via YAML.""" | ||
return True |
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,56 @@ | ||
"""FireflyIII Integration Sensor platform""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from homeassistant import config_entries, core | ||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
|
||
from .const import ( | ||
COORDINATOR, | ||
DOMAIN, | ||
FIREFLYIII_SENSOR_TYPES, | ||
FIREFLYIII_SERVER_SENSOR_TYPE, | ||
BinarySensorEntityDescription, | ||
FireflyiiiEntityBase, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: core.HomeAssistant, | ||
config_entry: config_entries.ConfigEntry, | ||
async_add_entities, | ||
) -> None: | ||
"""Setup sensors from a config entry created in the integrations UI.""" | ||
config = hass.data[DOMAIN][config_entry.entry_id] | ||
# Update our config to include new repos and remove those that have been removed. | ||
if config_entry.options: | ||
config.update(config_entry.options) | ||
|
||
coordinator = config[COORDINATOR] | ||
|
||
sensors = [ | ||
FireflyiiiServer( | ||
coordinator, FIREFLYIII_SENSOR_TYPES[FIREFLYIII_SERVER_SENSOR_TYPE] | ||
) | ||
] | ||
async_add_entities(sensors, update_before_add=True) | ||
|
||
|
||
class FireflyiiiServer(FireflyiiiEntityBase, BinarySensorEntity): | ||
"""Firefly Server Sensors""" | ||
|
||
def __init__( | ||
self, coordinator, entity_description: BinarySensorEntityDescription = None | ||
): | ||
super().__init__(coordinator, entity_description) | ||
|
||
self._available = True | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return if connected.""" | ||
return self.coordinator.last_update_success |
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,99 @@ | ||
"""FireflyIII Integration Calendar Plataform""" | ||
|
||
from __future__ import annotations | ||
|
||
import datetime | ||
import logging | ||
from typing import Any | ||
|
||
from homeassistant import config_entries, core | ||
from homeassistant.components.calendar import CalendarEntity, CalendarEvent | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .const import ( | ||
COORDINATOR, | ||
DOMAIN, | ||
FIREFLYIII_INVOICES_SENSOR_TYPE, | ||
FIREFLYIII_SENSOR_TYPES, | ||
EntityDescription, | ||
FireflyiiiEntityBase, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: core.HomeAssistant, | ||
config_entry: config_entries.ConfigEntry, | ||
async_add_entities, | ||
) -> None: | ||
"""Setup sensors from a config entry created in the integrations UI.""" | ||
config = hass.data[DOMAIN][config_entry.entry_id] | ||
# Update our config to include new repos and remove those that have been removed. | ||
if config_entry.options: | ||
config.update(config_entry.options) | ||
|
||
coordinator = config[COORDINATOR] | ||
|
||
invoices = [] | ||
if FIREFLYIII_INVOICES_SENSOR_TYPE in coordinator.api_data: | ||
obj = FireflyiiiInvoices( | ||
coordinator, FIREFLYIII_SENSOR_TYPES[FIREFLYIII_INVOICES_SENSOR_TYPE] | ||
) | ||
|
||
invoices.append(obj) | ||
|
||
sensors = [] | ||
sensors.extend(invoices) | ||
async_add_entities(sensors, update_before_add=True) | ||
|
||
|
||
class FireflyiiiInvoices(FireflyiiiEntityBase, CalendarEntity): | ||
"""Firefly Invoices Calendar""" | ||
|
||
def __init__( | ||
self, | ||
coordinator, | ||
entity_description: EntityDescription = None, | ||
data: dict = None, | ||
): | ||
self._data = data if data else {} | ||
super().__init__(coordinator, entity_description, self._data.get("id", 0)) | ||
|
||
self._attr_supported_features = [] | ||
|
||
self._available = True | ||
|
||
async def async_create_event(self, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def async_delete_event( | ||
self, | ||
uid: str, | ||
recurrence_id: str | None = None, | ||
recurrence_range: str | None = None, | ||
) -> None: | ||
pass | ||
|
||
async def async_update_event( | ||
self, | ||
uid: str, | ||
event: dict[str, Any], | ||
recurrence_id: str | None = None, | ||
recurrence_range: str | None = None, | ||
) -> None: | ||
pass | ||
|
||
@property | ||
def event(self) -> CalendarEvent | None: | ||
"""Return the next upcoming event.""" | ||
return None | ||
|
||
async def async_get_events( | ||
self, | ||
hass: HomeAssistant, | ||
start_date: datetime.datetime, | ||
end_date: datetime.datetime, | ||
) -> list[CalendarEvent]: | ||
"""Return calendar events within a datetime range.""" | ||
return [] |
Oops, something went wrong.