Compare commits
6 Commits
b0019fe794
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 90075b525b | |||
| 7598bb22ca | |||
| cea8287084 | |||
| 2f5756b1f6 | |||
| d65a469d7f | |||
| bf5ee44282 |
14
.github/workflows/hassfest.yml
vendored
Normal file
14
.github/workflows/hassfest.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
name: Validate with hassfest
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- uses: "actions/checkout@v3"
|
||||
- uses: home-assistant/actions/hassfest@master
|
||||
16
.github/workflows/validate.yml
vendored
Normal file
16
.github/workflows/validate.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
name: Validate
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
workflow_dispatch:
|
||||
permissions: {}
|
||||
jobs:
|
||||
validate-hacs:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: HACS validation
|
||||
uses: "hacs/action@main"
|
||||
with:
|
||||
category: "integration"
|
||||
@@ -1,9 +1,12 @@
|
||||
import aiohttp
|
||||
import voluptuous as vol
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
import logging
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, PLATFORMS
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -80,13 +83,17 @@ async def async_setup_entry(hass: HomeAssistant, entry):
|
||||
|
||||
hass.services.async_register(DOMAIN, "say", handle_say, schema=_SAY_SCHEMA)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry):
|
||||
hass.data[DOMAIN].pop(entry.entry_id, None)
|
||||
unloaded = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
if not hass.data[DOMAIN]:
|
||||
hass.services.async_remove(DOMAIN, "say")
|
||||
if unloaded:
|
||||
hass.data[DOMAIN].pop(entry.entry_id, None)
|
||||
|
||||
return True
|
||||
if not hass.data[DOMAIN]:
|
||||
hass.services.async_remove(DOMAIN, "say")
|
||||
|
||||
return unloaded
|
||||
|
||||
63
custom_components/jibo/binary_sensor.py
Normal file
63
custom_components/jibo/binary_sensor.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=30)
|
||||
_CONNECT_TIMEOUT = 5.0
|
||||
_JIBO_PORT = 8089
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
data = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
[JiboConnectivitySensor(entry, data["jibo_ip"], data["name"])],
|
||||
update_before_add=True,
|
||||
)
|
||||
|
||||
|
||||
class JiboConnectivitySensor(BinarySensorEntity):
|
||||
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
||||
_attr_should_poll = True
|
||||
|
||||
def __init__(self, entry: ConfigEntry, ip: str, name: str) -> None:
|
||||
self._ip = ip
|
||||
self._attr_unique_id = f"{entry.entry_id}_connectivity"
|
||||
self._attr_name = f"{name} Online"
|
||||
self._attr_is_on = False
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, entry.entry_id)},
|
||||
"name": name,
|
||||
"manufacturer": "Jibo Inc.",
|
||||
"model": "Jibo",
|
||||
}
|
||||
|
||||
async def async_update(self) -> None:
|
||||
try:
|
||||
_, writer = await asyncio.wait_for(
|
||||
asyncio.open_connection(self._ip, _JIBO_PORT),
|
||||
timeout=_CONNECT_TIMEOUT,
|
||||
)
|
||||
writer.close()
|
||||
try:
|
||||
await writer.wait_closed()
|
||||
except Exception:
|
||||
pass
|
||||
self._attr_is_on = True
|
||||
except (asyncio.TimeoutError, OSError):
|
||||
self._attr_is_on = False
|
||||
@@ -1 +1,2 @@
|
||||
DOMAIN = "jibo"
|
||||
DOMAIN = "jibo"
|
||||
PLATFORMS = ["binary_sensor"]
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
{
|
||||
"domain": "jibo",
|
||||
"name": "OpenJibo",
|
||||
"version": "0.1.0.alpha.2",
|
||||
"documentation": "https://jibohacks.zane.org/homeassistant/int",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@ZaneThePython"],
|
||||
"config_flow": true,
|
||||
"iot_class": "local_polling"
|
||||
}
|
||||
"dependencies": [],
|
||||
"documentation": "https://jibohacks.zane.org/homeassistant/int",
|
||||
"integration_type": "device",
|
||||
"iot_class": "local_polling",
|
||||
"issue_tracker": "https://github.com/ZaneThePython/openjibo-hacs/issues",
|
||||
"requirements": [],
|
||||
"version": "0.1.0.4"
|
||||
}
|
||||
|
||||
28
custom_components/jibo/translations/en.json
Normal file
28
custom_components/jibo/translations/en.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"config": {
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Add a Jibo Robot",
|
||||
"description": "Enter the details for your Jibo robot. The robot must be running the OpenJibo custom software with all ports exposed.",
|
||||
"data": {
|
||||
"name": "Robot Name",
|
||||
"jibo_ip": "IP Address"
|
||||
},
|
||||
"data_description": {
|
||||
"name": "A friendly name to identify this robot (e.g. Living Room Jibo).",
|
||||
"jibo_ip": "The local IP address of the robot on your network."
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "A Jibo robot with this IP address is already configured."
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"connectivity": {
|
||||
"name": "Online"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user