Skip to content

Commit

Permalink
Merge pull request #1476 from totaldebug/beta
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
marksie1988 authored Apr 8, 2024
2 parents b327da4 + 9c35802 commit 0ae638f
Show file tree
Hide file tree
Showing 44 changed files with 2,427 additions and 1,612 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

</div>



<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
Expand All @@ -61,8 +59,6 @@
</ol>
</details>



<!-- ABOUT THE PROJECT -->
## About The Project

Expand All @@ -81,10 +77,8 @@ Allowing for the use of both Google Calendars and CalDav, With two main viewing

Please keep in mind, these screenshots show a basic configuration, this card allows so much more customisation!


<p align="right">(<a href="#readme-top">back to top</a>)</p>


### Built With

[![typescript][typescript]][typescript-url]
Expand Down Expand Up @@ -156,7 +150,6 @@ Got something you would like to add? check out the contributing guide in the [do

<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- LICENSE -->
## License

Expand All @@ -166,7 +159,6 @@ Got something you would like to add? check out the contributing guide in the [do

<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- CONTACT -->
## Contact

Expand All @@ -185,7 +177,6 @@ Below are a list of resources that I used to assist with this project.

<p align="right">(<a href="#readme-top">back to top</a>)</p>


<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[release-shield]: https://img.shields.io/github/v/release/totaldebug/atomic-calendar-revive?color=ff7034&label=Release&sort=semver&style=flat-square
Expand All @@ -212,7 +203,6 @@ Below are a list of resources that I used to assist with this project.
[lines-url]: https://github.com/totaldebug/atomic-calendar-revive
[code-size]: https://img.shields.io/github/languages/code-size/totaldebug/atomic-calendar-revive?style=flat-square


[Sponsor]: https://img.shields.io/badge/sponsor-000?style=flat-square&logo=githubsponsors&logoColor=red
[Sponsor-url]: https://github.com/sponsors/marksie1988

Expand Down
1 change: 0 additions & 1 deletion docs/configuration/language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Language Options
noEventsForNextDaysText string v0.8.6 ``No events in the next days`` Custom text for ``No events in the next days`` text
noEventText string v4.1.0 ``No events`` Custom text for ``No events`` text, only if ``showNoEventsForToday`` or ``showNoEventDays`` is true
dateFormat string v0.7.2 ``LL`` Custom date format - see `list of localized formats <https://day.js.org/docs/en/display/format#localized-formats>`_
hoursFormat string v5.0.0 This is now set via your HA profile settings, you can still set this to override if required - see `List of all available formats <https://day.js.org/docs/en/display/format#list-of-all-available-formats`_
========================== ========= ======== ===============================================================================================================================================================================================================


Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Main Options
showNoEventDays boolean optional v4.1.0 ``false`` Shows days that have no events, instead of only showing event days
descLength integer optional v4.8.0 Sets the length of descriptions
hideDuplicates boolean optional v5.1.0 ``false`` Removes any duplicate items based on summary, start time and end time.
hideDeclined boolean optional v7.0.0 ``false`` show/hide events that have been declined
showDeclined boolean optional v7.0.0 ``false`` show/hide events that have been declined
showMultiDay boolean optional v7.0.0 ``false`` if set true will show multi-day events on each day
showMultiDayEventParts boolean optional v7.0.0 ``false`` if set true will show how many days in event and which day it is
hideFinishedEvents boolean optional v7.0.0 ``false`` if set true will hide any finished events
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atomic-calendar-revive",
"version": "9.6.2",
"version": "9.7.0-beta.1",
"description": "Calendar Card for Home Assistant",
"main": "atomic-calendar-revive.js",
"scripts": {
Expand Down Expand Up @@ -71,9 +71,10 @@
"@material/mwc-textfield": "^0.27.0",
"@mdi/js": "^7.4.47",
"@webcomponents/webcomponentsjs": "^2.8.0",
"custom-card-helpers": "^1.9.0",
"dayjs": "^1.11.10",
"lit": "^3.1.1",
"home-assistant-js-websocket": "^9.1.0",
"lit": "^3.0.2",
"memoize-one": "^6.0.0",
"npm": "^10.4.0",
"typescript": "^5.3.3"
},
Expand Down
79 changes: 79 additions & 0 deletions src/common/fire-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Polymer legacy event helpers used courtesy of the Polymer project.
//
// Copyright (c) 2017 The Polymer Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

declare global {
// tslint:disable-next-line
interface HASSDomEvents {}
}

export type ValidHassDomEvent = keyof HASSDomEvents;

export interface HASSDomEvent<T> extends Event {
detail: T;
}

/**
* Dispatches a custom event with an optional detail value.
*
* @param {string} type Name of event type.
* @param {*=} detail Detail value containing event-specific
* payload.
* @param {{ bubbles: (boolean|undefined),
* cancelable: (boolean|undefined),
* composed: (boolean|undefined) }=}
* options Object specifying options. These may include:
* `bubbles` (boolean, defaults to `true`),
* `cancelable` (boolean, defaults to false), and
* `node` on which to fire the event (HTMLElement, defaults to `this`).
* @return {Event} The new event that was fired.
*/
export const fireEvent = <HassEvent extends ValidHassDomEvent>(
node: HTMLElement | Window,
type: HassEvent,
detail?: HASSDomEvents[HassEvent],
options?: {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
},
) => {
options = options || {};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
detail = detail === null || detail === undefined ? {} : detail;
const event = new Event(type, {
bubbles: options.bubbles === undefined ? true : options.bubbles,
cancelable: Boolean(options.cancelable),
composed: options.composed === undefined ? true : options.composed,
});
(event as any).detail = detail;
node.dispatchEvent(event);
return event;
};
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export default {
allDayBottom: false, // show all day events at the bottom of the day
disableEventLink: false, // disables links to event calendar
disableLocationLink: false, // disables links to event calendar
disableCalLocationLink: false,
disableCalMonthLink: false, // disables the link on the month name in calendar mode
linkTarget: '_blank', // Target for links, can use any HTML target type
hideDeclined: false, // hide declined events in the calendar
showPrivate: true, // hide private events
showDeclined: true, // show declined events in the calendar
showPrivate: true, // show private events
showHiddenText: true, //show the hidden events text
showCalendarName: false,

Expand Down
15 changes: 9 additions & 6 deletions src/editor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ScopedRegistryHost } from '@lit-labs/scoped-registry-mixin';
import { HomeAssistant, LovelaceCardEditor, fireEvent } from 'custom-card-helpers';
import { CSSResult, LitElement, TemplateResult, html } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';

import { fireEvent } from './common/fire-event';
import defaultConfig from './defaults';
import localize from './localize/localize';
import { style } from './style-editor';
Expand All @@ -16,6 +16,8 @@ import {
TextProperty,
UnionProperty,
} from './types/editor';
import { HomeAssistant } from './types/homeassistant';
import { LovelaceCardEditor } from './types/lovelace';
import { formfieldDefinition } from '../elements/formfield';
import { selectDefinition } from '../elements/select';
import { switchDefinition } from '../elements/switch';
Expand Down Expand Up @@ -282,11 +284,6 @@ export class AtomicCalendarReviveEditor extends ScopedRegistryHost(LitElement) i
label: localize('main.fields.dateFormat'),
default: defaultConfig.dateFormat,
},
{
type: 'text',
name: 'hoursFormat',
label: localize('main.fields.hoursFormat'),
},
{
type: 'text',
name: 'eventTitle',
Expand Down Expand Up @@ -637,6 +634,8 @@ export class AtomicCalendarReviveEditor extends ScopedRegistryHost(LitElement) i
}
}
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
fireEvent(this, 'config-changed', { config: this._config });
}

Expand Down Expand Up @@ -861,6 +860,8 @@ export class AtomicCalendarReviveEditor extends ScopedRegistryHost(LitElement) i
});

this._config = Object.assign({}, this._config, { entities: entityObjects });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
fireEvent(this, 'config-changed', { config: this._config });
}
/**
Expand All @@ -882,6 +883,8 @@ export class AtomicCalendarReviveEditor extends ScopedRegistryHost(LitElement) i
}

this._config = Object.assign({}, this._config, { entities: entityObjects });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
fireEvent(this, 'config-changed', { config: this._config });
}
/**
Expand Down
44 changes: 23 additions & 21 deletions src/helpers/format-time.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { FrontendLocaleData, TimeFormat } from 'custom-card-helpers';
import { HassConfig } from 'home-assistant-js-websocket';
import memoizeOne from 'memoize-one';

/**
* Formats a number based on the specified language with thousands separator(s) and decimal character for better legibility.
* @param locale The user-selected language and number format, from `hass.locale`
*/
export const formatTime = (locale?: FrontendLocaleData): string => {
let format: string | string[] | undefined;
import { FrontendLocaleData, TimeFormat } from '../types/translation';

switch (locale?.time_format) {
case TimeFormat.am_pm:
format = 'hh:mma';
break;
case TimeFormat.twenty_four:
format = 'HH:mm';
break;
case TimeFormat.system:
format = undefined;
break;
default:
format = undefined;
export const useAmPm = memoizeOne((locale: FrontendLocaleData): boolean => {
if (locale.time_format === TimeFormat.language || locale.time_format === TimeFormat.system) {
const testLanguage = locale.time_format === TimeFormat.language ? locale.language : undefined;
const test = new Date().toLocaleString(testLanguage);
return test.includes('AM') || test.includes('PM');
}

return format ? format.toString() : '';
};
return locale.time_format === TimeFormat.am_pm;
});

export const formatTime = (dateObj: Date, locale: FrontendLocaleData, config: HassConfig) =>
formatTimeMem(locale, config.time_zone).format(dateObj);

const formatTimeMem = memoizeOne(
(locale: FrontendLocaleData, serverTimeZone: string) =>
new Intl.DateTimeFormat(locale.language === 'en' && !useAmPm(locale) ? 'en-u-hc-h23' : locale.language, {
hour: 'numeric',
minute: '2-digit',
hour12: useAmPm(locale),
timeZone: locale.time_zone === 'server' ? serverTimeZone : undefined,
}),
);
2 changes: 1 addition & 1 deletion src/helpers/get-default-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HomeAssistant } from 'custom-card-helpers';
import { HomeAssistant } from '../types/homeassistant';

export function getDefaultConfig(hass: HomeAssistant) {
// Get an array of calendar entities with their full objects
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/get-icon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HomeAssistant } from 'custom-card-helpers';
import { html } from 'lit';

import EventClass from '../lib/event.class';
import { atomicCardConfig } from '../types/config';
import { HomeAssistant } from '../types/homeassistant';

// Function to get the icon for a specific entity
export function getEntityIcon(entityId: string, hass: HomeAssistant): string | null {
Expand Down
34 changes: 34 additions & 0 deletions src/helpers/get-lovelace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { LovelaceConfig } from '../types/lovelace';

export function getLovelaceCast(): any {
let root: any = document.querySelector('hc-main');
root = root && root.shadowRoot;
root = root && root.querySelector('hc-lovelace');
root = root && root.shadowRoot;
root = root && (root.querySelector('hui-view') || root.querySelector('hui-panel-view'));
if (root) {
const ll = root.lovelace;
ll.current_view = root.___curView;
return ll;
}
return null;
}

export function getLovelace(): LovelaceConfig | null {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let root: any = document.querySelector('home-assistant');
root = root && root.shadowRoot;
root = root && root.querySelector('home-assistant-main');
root = root && root.shadowRoot;
root = root && root.querySelector('app-drawer-layout partial-panel-resolver, ha-drawer partial-panel-resolver');
root = (root && root.shadowRoot) || root;
root = root && root.querySelector('ha-panel-lovelace');
root = root && root.shadowRoot;
root = root && root.querySelector('hui-root');
if (root) {
const ll = root.lovelace;
ll.current_view = root.___curView;
return ll;
}
return null;
}
2 changes: 1 addition & 1 deletion src/helpers/globals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HomeAssistant } from 'custom-card-helpers';
import { HomeAssistant } from '../types/homeassistant';

// Globalise the hass object so that localize can utilise it.

Expand Down
Loading

0 comments on commit 0ae638f

Please sign in to comment.