Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosweet committed Apr 19, 2022
1 parent d749ed9 commit eb3908a
Show file tree
Hide file tree
Showing 25 changed files with 967 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
36 changes: 36 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Validate

on:
pull_request:
branches:
- main
push:
branches:
- main
schedule:
- cron: "0 0 * * *"

jobs:
validate-hassfest:
runs-on: ubuntu-latest
name: With hassfest
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v2

- name: ✅ Hassfest validation
uses: "home-assistant/actions/hassfest@master"

validate-hacs:
runs-on: ubuntu-latest
name: With HACS Action
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v2

- name: ✅ HACS validation
uses: hacs/action@main
with:
category: integration
comment: false
#ignore: brands wheels
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 caiosweet

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.
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Home Assistant - Custom Components Nasa APIs

![Nasa](assets/brand/logo.png)

Welcome to my repository Home Assistant - Custom Component NASA for the [nasa.gov][nasa] API.

The Nasa platform uses the Nasa APIs to know a lot of information, such as, the image of the day, on asteroids near the Earth, photos from Mars and much more.

[![hacs][hacsbadge]][hacs] [![Validate](https://github.com/caiosweet/Home-Assistant-custom-components-NASA/actions/workflows/validate.yaml/badge.svg)](https://github.com/caiosweet/Home-Assistant-custom-components-NASA/actions/workflows/validate.yaml)

[![GitHub latest release]][githubrelease] ![GitHub Release Date] [![Maintenancebadge]][maintenance] [![GitHub issuesbadge]][github issues]

[![Websitebadge]][website] [![Forum][forumbadge]][forum] [![telegrambadge]][telegram] [![facebookbadge]][facebook]

[![Don't buy me a coffee](https://img.shields.io/static/v1.svg?label=Don't%20buy%20me%20a%20coffee&message=🔔&color=black&logo=buy%20me%20a%20coffee&logoColor=white&labelColor=6f4e37)](https://paypal.me/hassiohelp)

---

## Introduction

> The goal is to integrate the largest number of Nasa APIs available, time and knowledge permitting.
> I am looking for a complete asynchronous python wrapper module for NASA's open APIs.
> This custom component is still in the development/testing phase. Bugs are still being worked out and breaking changes are common.
## Authentication

Although not strictly required to begin interacting with the NASA API, it is recommended to [Generate API Key][nasa].

## Information

TODO

## Installation

### Using [Home Assistant Community Store](https://hacs.xyz/) (recommended)

1. Click on HACS in the Home Assistant menu
2. Click on `Integrations`
3. Click the `EXPLORE & ADD REPOSITORIES` button
4. Search for `Nasa`
5. Click the `INSTALL THIS REPOSITORY IN HACS` button
6. Restart Home Assistant

## Configuration

### Config flow

To configure this integration go to: `Configurations` -> `Integrations` -> `ADD INTEGRATIONS` button, search for `Nasa` and configure the component.

You can also use following [My Home Assistant](http://my.home-assistant.io/) link

[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=nasa)

### Setup

Now the integration is added to HACS and available in the normal HA integration installation

1. In the HomeAssistant left menu, click `Configuration`
2. Click `Integrations`
3. Click `ADD INTEGRATION`
4. Type `Nasa` and select it
5. Enter the data:
1. **Apy Key**: default DEMO KEY
6. Configure the Optional:
1. [APOD] - Astronomy Picture of the Day
2. [InSight] - Mars Weather Service API
3. [EPIC] - Earth Polychromatic Imaging Camera
4. [NeoWs] - Asteroids Near Earth Object Web Service
5. [Exoplanet] - Exoplanet Archive
6. Update interval (minutes, default 120)

Once you done that, you’re ready to start.

> NB: If you leave the API KEY field blank, the DEMO KEY will be used. It's fine to start with, but it depends on the things to check out.
## TODO Description of the sensors

## TODO Preview - Usage

Preview

![Logo](assets/brand/icon.png)

## License

Information provided by [_NASA APIs_](https://api.nasa.gov/) a central catalog and key service for public APIs.

## Contributions are welcome

---

## Trademark Legal Notices

All product names, trademarks and registered trademarks in the images in this repository, are property of their respective owners.
All images in this repository are used by the author for identification purposes only.
The use of these names, trademarks and brands appearing in these image files, do not imply endorsement.

<!--- Badge -->

[hacs]: https://github.com/custom-components/hacs
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-41BDF5.svg
[hacs_integration]: https://github.com/hacs/integration
[github latest release]: https://img.shields.io/github/v/release/caiosweet/Home-Assistant-custom-components-NASA
[githubrelease]: https://github.com/caiosweet/Home-Assistant-custom-components-NASA/releases
[github release date]: https://img.shields.io/github/release-date/caiosweet/Home-Assistant-custom-components-NASA
[maintenancebadge]: https://img.shields.io/badge/Maintained%3F-Yes-brightgreen.svg
[maintenance]: https://github.com/caiosweet/Home-Assistant-custom-components-NASA/graphs/commit-activity
[github issuesbadge]: https://img.shields.io/github/issues/caiosweet/Home-Assistant-custom-components-NASA
[github issues]: https://github.com/caiosweet/Home-Assistant-custom-components-NASA/issues
[website]: https://hassiohelp.eu/
[websitebadge]: https://img.shields.io/website?down_message=Offline&label=HssioHelp&logoColor=blue&up_message=Online&url=https%3A%2F%2Fhassiohelp.eu
[telegram]: https://t.me/HassioHelp
[telegrambadge]: https://img.shields.io/badge/Chat-Telegram-blue?logo=Telegram
[facebook]: https://www.facebook.com/groups/2062381507393179/
[facebookbadge]: https://img.shields.io/badge/Group-Facebook-blue?logo=Facebook
[forum]: https://forum.hassiohelp.eu/
[forumbadge]: https://img.shields.io/badge/HassioHelp-Forum-blue?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA0ppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ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2Bc7JwFn//KHKtAI8IkVejFgIgY8p2etEB7cPDbF32wSE8pwx926XTx6pAcPxxmFlzIo2o/qPy84sb4JTSMb7v3qiGFhJIaAzw1wbkmh8tu4IrqKm4v347V1qmvQGKvjJjEyf7v/pX3GmrGp%2BtT73UDyRHCPLMBDKwUj801dl4P7Fwc8fh0rLwiaBrp2dN2Do%2Bxfb%2Bd%2BE2GwEe%2BEPTYaW1gNQUiKaBP9T/ggwAJik5dEKYSC3AAAAAElFTkSuQmCC

<!--- Link -->
[APOD]: https://apod.nasa.gov/apod/astropix.html
[EPIC]: https://epic.gsfc.nasa.gov/
[Exoplanet]: https://exoplanetarchive.ipac.caltech.edu/index.html
[InSight]: https://mars.nasa.gov/insight/weather/
[NeoWs]: http://neo.jpl.nasa.gov/
[nasa]: https://api.nasa.gov/
1 change: 1 addition & 0 deletions assets/brand/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Binary file added assets/brand/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/brand/icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/brand/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/brand/logo@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/images/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Binary file added assets/images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions custom_components/nasa/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""The Nasa integration."""
from __future__ import annotations

import aionasa

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_SCAN_INTERVAL
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import (
CONF_API_CATEGORY,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
LOGGER,
PLATFORMS,
STARTUP_MESSAGE,
)
from .coordinator import NasaDataUpdateCoordinator


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up the Nasa integration from a config entry."""
hass.data.setdefault(DOMAIN, {})

LOGGER.info(STARTUP_MESSAGE)

api_key: str = entry.data.get(CONF_API_KEY, "DEMO_KEY")
session = async_get_clientsession(hass)

sourceapis: list[str] = entry.options.get(CONF_API_CATEGORY, [])
interval: int = entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)

for sourceapi in sourceapis:
api = getattr(aionasa, sourceapi)(api_key=api_key, session=session)

coordinator = NasaDataUpdateCoordinator(
hass=hass,
api=api,
name=sourceapi,
update_interval=interval,
)
await coordinator.async_config_entry_first_refresh()
hass.data[DOMAIN][sourceapi] = coordinator

async_cleanup_device_registry(hass=hass, entry=entry)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))

return True


@callback
def async_cleanup_device_registry(
hass: HomeAssistant,
entry: ConfigEntry,
) -> None:
"""Remove entries form device registry if we no longer track the api."""
device_registry = dr.async_get(hass)
devices = dr.async_entries_for_config_entry(
registry=device_registry,
config_entry_id=entry.entry_id,
)
for device in devices:
for item in device.identifiers:
if DOMAIN == item[0] and item[1] not in entry.options[CONF_API_CATEGORY]:
LOGGER.debug(
"Unlinking device %s for unchecked category %s from config entry %s",
device.id,
item[1],
entry.entry_id,
)
device_registry.async_update_device(
device.id, remove_config_entry_id=entry.entry_id
)
break


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data.pop(DOMAIN)
return unload_ok


async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle an options update."""
await hass.config_entries.async_reload(entry.entry_id)
Loading

0 comments on commit eb3908a

Please sign in to comment.