Skip to content

Commit

Permalink
Merge pull request #4 from krahabb/dev
Browse files Browse the repository at this point in the history
upgrade HA core compatibility to 2024.9
  • Loading branch information
krahabb authored Sep 12, 2024
2 parents 1ab3490 + 56fdb77 commit 8dac5d8
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 17 deletions.
20 changes: 5 additions & 15 deletions custom_components/motion_frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import aiohttp
from homeassistant.components import webhook
from homeassistant.config_entries import ConfigEntryNotReady
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand Down Expand Up @@ -161,25 +161,14 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"exception (%s) setting up media_source directory", str(err)
)

for p in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, p)
)
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)

return True


async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(config_entry, p)
for p in PLATFORMS
]
)
)

if unload_ok:
if await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS):
hassdata = hass.data[DOMAIN]
api: MotionFrontendApi = hassdata[config_entry.entry_id]
await api.close()
Expand All @@ -195,8 +184,9 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
api.unsub_entry_update_listener()
api.unsub_entry_update_listener = None
hassdata.pop(config_entry.entry_id)
return True

return unload_ok
return False


class MotionFrontendApi(MotionHttpClient):
Expand Down
137 changes: 137 additions & 0 deletions dist/motion_frontend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
LitElement,
html,
customElement,
property,
CSSResult,
TemplateResult,
css,
PropertyValues,
internalProperty,
} from 'lit-element';
import {
HomeAssistant,
hasConfigOrEntityChanged,
hasAction,
ActionHandlerEvent,
handleAction,
//LovelaceCardEditor,
getLovelace,
ActionConfig, LovelaceCard, LovelaceCardConfig, LovelaceCardEditor
} from 'custom-card-helpers'; // This is a community maintained npm module with common helper functions/types


export const CARD_VERSION = '0.0.1';
// TODO Add your configuration elements here for type-checking
/*
export interface BoilerplateCardConfig extends LovelaceCardConfig {
type: string;
name?: string;
show_warning?: boolean;
show_error?: boolean;
test_gui?: boolean;
entity?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
}*/

function localize(msg, search = '', replace = '') {
return msg
}

class MotionFrontendCameraCard extends LitElement {

/*static async getConfigElement() {
return document.createElement('motion-frontend-camera-card-editor');
}
static getStubConfig() {
return {};
}*/

static get properties() {
return {
hass: {},
config: {}
};
}


setConfig(config) {
if (!config) {
throw new Error(localize('common.invalid_configuration'));
}

if (config.test_gui) {
getLovelace().setEditMode(true);
}

this.config = {
name: 'Motion Frontend Camera Name',
...config,
};
}


render() {
// TODO Check for stateObj or other necessary things and render a warning if missing
if (this.config.show_warning) {
return this._showWarning(localize('common.show_warning'));
}

if (this.config.show_error) {
return this._showError(localize('common.show_error'));
}

return html`
<ha-card
.header=${this.config.name}
@action=${this._handleAction}
.actionHandler=${actionHandler({
hasHold: hasAction(this.config.hold_action),
hasDoubleClick: hasAction(this.config.double_tap_action),
})}
tabindex="0"
.label=${`Boilerplate: ${this.config.entity || 'No Entity Defined'}`}
></ha-card>
`;
}

_handleAction(ev) {
if (this.hass && this.config && ev.detail.action) {
handleAction(this, this.hass, this.config, ev.detail.action);
}
}

_showWarning(warning) {
return html`
<hui-warning>${warning}</hui-warning>
`;
}

_showError(error) {
const errorCard = document.createElement('hui-error-card');
errorCard.setConfig({
type: 'error',
error,
origConfig: this.config,
});

return html`
${errorCard}
`;
}

}


// This puts your card into the UI card picker dialog
window.customCards = window.customCards || [];
window.customCards.push({
type: "motion-frontend-camera-card",
name: "Motion Frontend Camera Card",
preview: false, // Optional - defaults to false
description: "A custom card made by me!" // Optional
});
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Motion Frontend",
"homeassistant": "2024.1.0",
"homeassistant": "2024.9.0",
"render_readme": true
}
3 changes: 2 additions & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pytest-homeassistant-custom-component==0.3.2
#pytest-homeassistant-custom-component @ git+https://github.com/MatthewFlamm/[email protected] # HA core 2024.1.0
pytest-homeassistant-custom-component @ git+https://github.com/MatthewFlamm/[email protected] # HA core 2024.3.0
#pytest-homeassistant-custom-component @ git+https://github.com/MatthewFlamm/[email protected] # HA core 2024.3.0
pytest-homeassistant-custom-component @ git+https://github.com/MatthewFlamm/[email protected] # HA core 2024.9.1
1 change: 1 addition & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ cd "$(dirname "$0")/.."
apt update
apt -y install ffmpeg
apt -y install libpcap-dev
apt -y install libturbojpeg0

python3 -m pip install --requirement requirements_test.txt

0 comments on commit 8dac5d8

Please sign in to comment.