Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/build_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
exetico committed Dec 3, 2023
2 parents c2d6caa + bd68d67 commit ade6428
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}
branch: ${{ github.ref_name }}
51 changes: 28 additions & 23 deletions docs/_docs/floorplan/floorplan-examples.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1"
}
}
}
72 changes: 42 additions & 30 deletions src/components/floorplan/floorplan-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ export class FloorplanElement extends LitElement {
<div id="floorplan"></div>
<div id="log" style="display: ${this.isShowLog ? 'block' : 'none'};">
<a href="#" onclick="return false;" @click=${this.clearLog
}>Clear log<a/>
<a href="#" onclick="return false;" @click=${
this.clearLog
}>Clear log<a/>
<ul></ul>
</div>
</div>
Expand Down Expand Up @@ -349,8 +350,9 @@ export class FloorplanElement extends LitElement {
script.onerror = (err) => {
reject(
new URIError(
`${(err as unknown as Record<string, Record<string, unknown>>).target
.src
`${
(err as unknown as Record<string, Record<string, unknown>>).target
.src
}`
)
);
Expand Down Expand Up @@ -1269,13 +1271,13 @@ export class FloorplanElement extends LitElement {

const singleTapContext = singleTapAction
? new FloorplanClickContext(
this,
entityId,
elementId,
svgElementInfo,
ruleInfo,
singleTapAction
)
this,
entityId,
elementId,
svgElementInfo,
ruleInfo,
singleTapAction
)
: false;

// Use simple function without delay, if doubleTap is not in use
Expand All @@ -1285,13 +1287,13 @@ export class FloorplanElement extends LitElement {
if (doubleTapAction) {
const doubleTapContext = doubleTapAction
? new FloorplanClickContext(
this,
entityId,
elementId,
svgElementInfo,
ruleInfo,
doubleTapAction
)
this,
entityId,
elementId,
svgElementInfo,
ruleInfo,
doubleTapAction
)
: false;

ManyClicks.observe(element as HTMLElement | SVGElement);
Expand Down Expand Up @@ -1387,7 +1389,10 @@ export class FloorplanElement extends LitElement {
const deviceId = Utils.deviceId();

for (const entityId of entityIds) {
if (entityId === `sensor.ha_floorplan_${deviceId}` && !changedEntityIds.has(entityId)) {
if (
entityId === `sensor.ha_floorplan_${deviceId}` &&
!changedEntityIds.has(entityId)
) {
changedEntityIds.add(entityId);
} else {
const entityInfo = this.entityInfos[entityId];
Expand Down Expand Up @@ -1493,12 +1498,18 @@ export class FloorplanElement extends LitElement {
}
}

handleEntityIdSetHoverOver(entityId: string, svgElementInfo: FloorplanSvgElementInfo): void {
handleEntityIdSetHoverOver(
entityId: string,
svgElementInfo: FloorplanSvgElementInfo
): void {
const entityInfo = this.entityInfos[entityId];
if (entityInfo) this.handleEntitySetHoverOver(entityInfo, svgElementInfo);
}

handleEntitySetHoverOver(entityInfo: FloorplanEntityInfo, svgElementInfo: FloorplanSvgElementInfo): void {
handleEntitySetHoverOver(
entityInfo: FloorplanEntityInfo,
svgElementInfo: FloorplanSvgElementInfo
): void {
const entityId = entityInfo.entityId as string;
const entityState = this.hass.states[entityId];

Expand All @@ -1511,7 +1522,7 @@ export class FloorplanElement extends LitElement {
isHoverInfo ||
(typeof ruleInfo.rule.hover_action === 'object' &&
(ruleInfo.rule.hover_action as FloorplanActionConfig).action ===
'hover-info');
'hover-info');
isHoverInfo =
isHoverInfo ||
(Array.isArray(ruleInfo.rule.hover_action) &&
Expand Down Expand Up @@ -1539,8 +1550,9 @@ export class FloorplanElement extends LitElement {

Object.keys(entityState.attributes).map((key) => {
if (!hoverInfoFilter.has(key)) {
titleText += `${key}: ${(entityState.attributes as Record<string, unknown>)[key]
}\n`;
titleText += `${key}: ${
(entityState.attributes as Record<string, unknown>)[key]
}\n`;
}
});
titleText += '\n';
Expand All @@ -1555,15 +1567,13 @@ export class FloorplanElement extends LitElement {
titleElement.textContent = titleText;
});
}
}
else if (ruleInfo.rule.hover_action) {
} else if (ruleInfo.rule.hover_action) {
this.handleActions(
ruleInfo.rule.hover_action,
entityInfo.entityId,
svgElementInfo,
ruleInfo
);

}
}
}
Expand Down Expand Up @@ -1719,7 +1729,7 @@ export class FloorplanElement extends LitElement {
if (
!confirm(
actionConfig.confirmation.text ||
`Are you sure you want to ${actionConfig.action}?`
`Are you sure you want to ${actionConfig.action}?`
)
) {
return;
Expand Down Expand Up @@ -2112,7 +2122,9 @@ export class FloorplanElement extends LitElement {
: (serviceData.text as string);

// If the text has linebreakes, setText will split them up, into more than a single tspan element. Each tspan will use the shift y axis as a offset (except for the first element)
const shiftYAxis = actionConfig.service_data?.shift_y_axis ? actionConfig.service_data?.shift_y_axis : '1em';
const shiftYAxis = actionConfig.service_data?.shift_y_axis
? actionConfig.service_data?.shift_y_axis
: '1em';
Utils.setText(targetSvgElement, text, shiftYAxis);
}
break;
Expand Down Expand Up @@ -2394,4 +2406,4 @@ export class FloorplanElement extends LitElement {
logDebug(area: string, message: string): void {
this.logger.log('debug', `${area} ${message}`);
}
}
}
6 changes: 3 additions & 3 deletions src/components/floorplan/lib/floorplan-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export class FloorplanSvgElementInfo {
public svgElement: SVGGraphicsElement,
public originalSvgElement: SVGGraphicsElement,
public originalBBox: DOMRect | null
) { }
) {}
}

export class FloorplanRuleInfo {
svgElementInfos: { [key: string]: FloorplanSvgElementInfo } = {};
imageUrl!: string;
imageLoader!: number | undefined;

constructor(public rule: FloorplanRuleConfig) { }
constructor(public rule: FloorplanRuleConfig) {}
}

export class FloorplanEntityInfo {
Expand All @@ -48,5 +48,5 @@ export class FloorplanClickContext {
public svgElementInfo: FloorplanSvgElementInfo,
public ruleInfo: FloorplanRuleInfo,
public actions: Array<FloorplanActionConfig>
) { }
) {}
}
4 changes: 2 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Utils {
textElement.textContent = '';

// Note the user about the intended change in a dataset
textElement.dataset.ha_floorplan_notice = 'The text_set function splitted your text into multiple tspans. Only the style of the first tspan is preserved. The style from the original tspan is reused on every tspan. The x and y are calculated on basis of the first tspan or text-element.';
textElement.dataset.ha_floorplan_notice = 'The text_set function split your text into multiple tspans. Only the style of the first tspan is preserved. The style from the original tspan is reused on every tspan. The x and y are calculated on the basis of the first tspan or text-element.';

// Get x location of text, if no found, set to 0
const textXPosition = textElement.getAttribute('x') || '0';
Expand Down Expand Up @@ -394,4 +394,4 @@ export class Utils {
}
return localStorage[ID_BROWER_KEY];
}
}
}

0 comments on commit ade6428

Please sign in to comment.