Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

3.7.3 rewrite #48

Merged
merged 10 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

91 changes: 0 additions & 91 deletions custom_components/jvc_projectors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,92 +1 @@
"""The JVC Projector integration."""

from __future__ import annotations
import logging
from jvc_projector.jvc_projector import JVCProjectorCoordinator, JVCInput
from homeassistant import config_entries
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_TIMEOUT,
Platform,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from .const import DOMAIN, PLATFORM_SCHEMA

_LOGGER = logging.getLogger("JVC_projectors")


async def async_setup_entry(hass, entry):
"""Set up JVC Projector from a config entry."""
host = entry.data.get(CONF_HOST)
password = entry.data.get(CONF_PASSWORD)

timeout = entry.data.get(CONF_TIMEOUT, 3)
port = 20554
options = JVCInput(host, password, port, timeout)
# Create a coordinator or directly set up your entities with the provided information
coordinator = JVCProjectorCoordinator(options, _LOGGER)

# Store the coordinator in hass.data for use by your platform (e.g., remote)
hass.data[DOMAIN] = coordinator
# Forward the setup to the platform, e.g., remote
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, Platform.REMOTE)
)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
_LOGGER.debug("Set up coordinator")

return True


async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload JVC Projector configuration entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)


async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the component from configuration.yaml."""
if DOMAIN not in config:
return True
for conf in config[DOMAIN]:
# Check if an entry for this configuration already exists
if any(
entry.data.get(PLATFORM_SCHEMA) == conf[PLATFORM_SCHEMA]
for entry in hass.config_entries.async_entries(DOMAIN)
):
continue

# If the entry does not exist, create a new config entry
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf
)
)

return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Handle unloading of JVC Projector integration."""
# Unload your integration's platforms (e.g., 'remote', 'sensor', etc.)
_LOGGER.debug("Unloading JVC Projector integration")
try:
coordinator: JVCProjectorCoordinator = hass.data[DOMAIN]
await coordinator.close_connection()
except Exception as e:
_LOGGER.error("Error closing JVC Projector connection - %s", e)
unload_ok = await hass.config_entries.async_forward_entry_unload(
entry, Platform.REMOTE
)

# If you have other resources to unload (listeners, services, etc.), do it here
_LOGGER.debug("Unloaded JVC Projector integration")
# Return True if unload was successful
try:
hass.data.pop(DOMAIN)
except KeyError:
pass
return unload_ok
118 changes: 0 additions & 118 deletions custom_components/jvc_projectors/config_flow.py

This file was deleted.

25 changes: 3 additions & 22 deletions custom_components/jvc_projectors/const.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
"""Constants for the JVC Projector integration."""
import voluptuous as vol
from homeassistant.components.remote import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
CONF_PASSWORD,
CONF_TIMEOUT,
CONF_SCAN_INTERVAL,
)
from homeassistant.helpers import config_validation as cv
DOMAIN = "jvc_projectors"

# Services
INFO_COMMAND = "info"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PASSWORD): cv.string,
vol.Required(CONF_SCAN_INTERVAL): cv.time_period,
vol.Optional(CONF_TIMEOUT): cv.positive_int,
}
)
DOMAIN = "jvc_projectors"
NAME = "JVC Projector Custom"
MANUFACTURER = "JVC"
11 changes: 4 additions & 7 deletions custom_components/jvc_projectors/manifest.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
"domain": "jvc_projectors",
"name": "JVC Projector",
"config_flow": true,
"documentation": "https://github.com/iloveicedgreentea/jvc_homeassistant",
"config_flow": false,
"documentation": "https://www.home-assistant.io/integrations/jvc_projector",
"requirements": [
"pyjvc==4.4.0"
"pyjvc==5.0.0"
],
"ssdp": [],
"zeroconf": [],
"homekit": {},
"dependencies": [],
"loggers": [
"custom_components.jvc_projectors"
],
"codeowners": [
"@iloveicedgreentea"
],
"iot_class": "local_polling",
"version": "4.2.9"
"version": "5.0.0"
}
Loading