@homebridge-plugins/homebridge-wemo
Version:
Homebridge plugin to integrate Wemo devices into HomeKit.
352 lines (348 loc) • 13.4 kB
HTML
<style>
.dark-mode {
background-color: #242424;
color: lightgrey;
.form-control {
background-color: #333333 ;
border: none ;
color: #eeeeee ;
}
thead, tbody, tr {
border-style: hidden;
}
th {
color: #eeeeee ;
font-weight: 500 ;
}
}
select {
background-image:
linear-gradient(45deg, transparent 50%, gray 50%),
linear-gradient(135deg, gray 50%, transparent 50%),
linear-gradient(to right, #ccc, #ccc);
background-position:
calc(100% - 20px) calc(1em + 2px),
calc(100% - 15px) calc(1em + 2px),
calc(100% - 2.5em) 0.5em;
background-size:
5px 5px,
5px 5px,
1px 1.5em;
background-repeat: no-repeat;
}
</style>
<p class="text-center">
<img
src="https://user-images.githubusercontent.com/43026681/126868557-d0983348-d124-4247-bea9-7dcc62849cdf.png"
alt="homebridge-wemo logo"
style="width: 60%;"
/>
</p>
<div id="pageIntro" class="text-center" style="display: none;">
<p class="lead">Thank you for installing <strong>homebridge-wemo</strong></p>
<p>Remember to click Save on the next page</p>
<button type="button" class="btn btn-primary" id="introContinue">Continue →</button>
</div>
<div
id="menuWrapper"
class="btn-group w-100 mb-0"
role="group"
aria-label="UI Menu"
style="display: none;"
>
<button type="button" class="btn btn-primary ml-0" id="menuSettings">Settings</button>
<button type="button" class="btn btn-primary" id="menuDevices">My Devices</button>
<button type="button" class="btn btn-primary mr-0" id="menuHome">Support</button>
</div>
<div id="pageDevices" class="mt-4" style="display: none;">
<div id="deviceInfo">
<form>
<div class="form-group">
<select class="form-control" id="deviceSelect"></select>
</div>
</form>
<table class="table w-100 mt-3" id="deviceTable" style="display: none;">
<thead>
<tr class="table-active">
<th scope="col" style="width: 40%;">Device Name</th>
<th scope="col" style="width: 60%;" id="displayName"></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">HTTP Status</th>
<td id="http_status"></td>
</tr>
<tr>
<th scope="row">UPnP Status</th>
<td id="upnp_status"></td>
</tr>
<tr>
<th scope="row">IP Address</th>
<td id="ipAddress"></td>
</tr>
<tr>
<th scope="row">Port</th>
<td id="port"></td>
</tr>
<tr>
<th scope="row">UPnP Info</th>
<td id="upnpInfo"></td>
</tr>
<tr>
<th scope="row">Serial Number</th>
<td id="serialNumber"></td>
</tr>
<tr>
<th scope="row">MAC Address</th>
<td id="macAddress"></td>
</tr>
<tr>
<th scope="row">Firmware</th>
<td id="firmware"></td>
</tr>
<tr>
<td colspan="2" style="text-align: center" id="imgIcon"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="pageSupport" class="mt-4" style="display: none;">
<p class="text-center lead">Thank you for using <strong>homebridge-wemo</strong></p>
<p class="text-center">The links below will take you to our GitHub wiki</p>
<h4>Setup</h4>
<ul>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/wiki/Installation" target="_blank"
>Installation</a
>
</li>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/wiki/Configuration" target="_blank"
>Configuration</a
>
</li>
<li>
<a href="https://github.com/homebridge/homebridge/wiki/How-to-Install-Alternate-Plugin-Versions" target="_blank"
>Beta Version</a
>
</li>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/wiki/Node-Version" target="_blank"
>Node Version</a
>
</li>
</ul>
<h4>Features</h4>
<ul>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/wiki/Supported-Devices" target="_blank"
>Supported Devices</a
>
</li>
</ul>
<h4>Help/About</h4>
<ul>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/wiki/Common-Errors" target="_blank"
>Common Errors</a
>
</li>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/issues/new/choose" target="_blank"
>Support Request</a
>
</li>
<li>
<a href="https://github.com/homebridge-plugins/homebridge-wemo/blob/latest/CHANGELOG.md" target="_blank"
>Changelog</a
>
</li>
<li><a href="https://github.com/sponsors/bwp91" target="_blank">About Me</a></li>
</ul>
<h4>Credits</h4>
<ul>
<li>
To the creator of this plugin:
<a href="https://github.com/rudders" target="_blank">@rudders</a>, and to
<a href="https://github.com/devbobo" target="_blank">@devbobo</a> for his contributions.
</li>
<li>
To the creator of
<a href="https://github.com/timonreinhard/wemo-client" target="_blank">wemo-client</a> (which
is now contained within this plugin):
<a href="https://github.com/timonreinhard" target="_blank">@timonreinhard</a>.
</li>
<li>
To <a href="http://www.hardill.me.uk/wordpress/tag/wemo/" target="_blank">Ben Hardill</a> for
his research on Wemo devices.
</li>
<li>To all users who have helped/tested to enable functionality for new devices.</li>
<li>
To the creators/contributors of
<a href="https://github.com/simont77/fakegato-history" target="_blank">Fakegato</a>:
<a href="https://github.com/simont77" target="_blank">@simont77</a> and
<a href="https://github.com/NorthernMan54" target="_blank">@NorthernMan54</a>.
</li>
<li>
To the creator of the awesome plugin header logo:
<a href="https://www.instagram.com/keryan.me" target="_blank">Keryan Belahcene</a>.
</li>
<li>
To the creators/contributors of
<a href="https://homebridge.io" target="_blank">Homebridge</a> who make this plugin possible.
</li>
</ul>
<h4>Disclaimer</h4>
<ul>
<li>
I am in no way affiliated with Belkin/Wemo and this plugin is a personal project that I
maintain in my free time.
</li>
<li>Use this plugin entirely at your own risk - please see licence for more information.</li>
</ul>
</div>
<script>
;(async () => {
try {
const currentConfig = await homebridge.getPluginConfig()
showIntro = () => {
homebridge.disableSaveButton?.()
const introContinue = document.getElementById('introContinue')
introContinue.addEventListener('click', () => {
homebridge.showSpinner()
document.getElementById('pageIntro').style.display = 'none'
document.getElementById('menuWrapper').style.display = 'inline-flex'
showSettings()
homebridge.hideSpinner()
})
document.getElementById('pageIntro').style.display = 'block'
}
showDevices = async () => {
homebridge.showSpinner()
homebridge.disableSaveButton?.()
homebridge.hideSchemaForm()
document.getElementById('menuHome').classList.remove('btn-elegant')
document.getElementById('menuHome').classList.add('btn-primary')
document.getElementById('menuDevices').classList.add('btn-elegant')
document.getElementById('menuDevices').classList.remove('btn-primary')
document.getElementById('menuSettings').classList.remove('btn-elegant')
document.getElementById('menuSettings').classList.add('btn-primary')
document.getElementById('pageSupport').style.display = 'none'
document.getElementById('pageDevices').style.display = 'block'
const cachedAccessories =
typeof homebridge.getCachedAccessories === 'function'
? await homebridge.getCachedAccessories()
: await homebridge.request('/getCachedAccessories')
if (cachedAccessories.length > 0) {
cachedAccessories.sort((a, b) => {
return a.displayName.toLowerCase() > b.displayName.toLowerCase()
? 1
: b.displayName.toLowerCase() > a.displayName.toLowerCase()
? -1
: 0
})
}
const deviceSelect = document.getElementById('deviceSelect')
deviceSelect.innerHTML = ''
cachedAccessories.forEach(a => {
const option = document.createElement('option')
option.text = a.displayName
option.value = a.context.serialNumber
deviceSelect.add(option)
})
showDeviceInfo = async serialNumber => {
homebridge.showSpinner()
const thisAcc = cachedAccessories.find(x => x.context.serialNumber === serialNumber)
const context = thisAcc.context
document.getElementById('displayName').innerHTML = thisAcc.displayName
document.getElementById('http_status').innerHTML = context.httpOnline
? '<i class="fas fa-circle mr-1 green-text"></i> Yes'
: '<i class="fas fa-circle mr-1 red-text"></i> No'
document.getElementById('upnp_status').innerHTML = context.upnpOnline
? '<i class="fas fa-circle mr-1 green-text"></i> Yes'
: '<i class="fas fa-circle mr-1 red-text"></i> No'
document.getElementById('ipAddress').innerHTML = context.ipAddress || 'N/A'
document.getElementById('port').innerHTML = context.port || 'N/A'
document.getElementById('upnpInfo').innerHTML =
context.ipAddress && context.port
? '<a href="http://' +
context.ipAddress +
':' +
context.port +
'/setup.xml" target="_blank" class="primary-text">Visit XML →</a>'
: 'N/A'
document.getElementById('serialNumber').innerHTML = context.serialNumber || 'N/A'
document.getElementById('macAddress').innerHTML = context.macAddress || 'N/A'
document.getElementById('firmware').innerHTML = context.firmware || 'N/A'
document.getElementById('imgIcon').innerHTML =
context.icon && context.ipAddress && context.port
? '<img src="http://' +
context.ipAddress +
':' +
context.port +
'/' +
context.icon +
'" style="width: 150px;">'
: ''
document.getElementById('deviceTable').style.display = 'inline-table'
homebridge.hideSpinner()
}
deviceSelect.addEventListener('change', event => showDeviceInfo(event.target.value))
if (cachedAccessories.length > 0) {
showDeviceInfo(cachedAccessories[0].context.serialNumber)
} else {
const option = document.createElement('option')
option.text = 'No Devices'
deviceSelect.add(option)
deviceSelect.disabled = true
}
homebridge.hideSpinner()
}
showSupport = () => {
homebridge.showSpinner()
homebridge.disableSaveButton?.()
homebridge.hideSchemaForm()
document.getElementById('menuHome').classList.add('btn-elegant')
document.getElementById('menuHome').classList.remove('btn-primary')
document.getElementById('menuDevices').classList.remove('btn-elegant')
document.getElementById('menuDevices').classList.add('btn-primary')
document.getElementById('menuSettings').classList.remove('btn-elegant')
document.getElementById('menuSettings').classList.add('btn-primary')
document.getElementById('pageSupport').style.display = 'block'
document.getElementById('pageDevices').style.display = 'none'
homebridge.hideSpinner()
}
showSettings = () => {
homebridge.showSpinner()
homebridge.enableSaveButton?.()
document.getElementById('menuHome').classList.remove('btn-elegant')
document.getElementById('menuHome').classList.add('btn-primary')
document.getElementById('menuDevices').classList.remove('btn-elegant')
document.getElementById('menuDevices').classList.add('btn-primary')
document.getElementById('menuSettings').classList.add('btn-elegant')
document.getElementById('menuSettings').classList.remove('btn-primary')
document.getElementById('pageSupport').style.display = 'none'
document.getElementById('pageDevices').style.display = 'none'
homebridge.showSchemaForm()
homebridge.hideSpinner()
}
menuHome.addEventListener('click', () => showSupport())
menuDevices.addEventListener('click', () => showDevices())
menuSettings.addEventListener('click', () => showSettings())
if (currentConfig.length) {
document.getElementById('menuWrapper').style.display = 'inline-flex'
showSettings()
} else {
currentConfig.push({ name: 'Wemo' })
await homebridge.updatePluginConfig(currentConfig)
showIntro()
}
} catch (err) {
homebridge.toast.error(err.message, 'Error')
} finally {
homebridge.hideSpinner()
}
})()
</script>