def state(ctx, dev: SmartDevice): """Print out device state and versions.""" asyncio.run(dev.update()) click.echo(click.style(f"== {dev.alias} - {dev.model} ==", bold=True)) click.echo( click.style( "Device state: {}".format("ON" if dev.is_on else "OFF"), fg="green" if dev.is_on else "red", )) if dev.is_strip: for plug in dev.plugs: # type: ignore asyncio.run(plug.update()) is_on = plug.is_on alias = plug.alias click.echo( click.style( " * {} state: {}".format(alias, ("ON" if is_on else "OFF")), fg="green" if is_on else "red", )) click.echo(f"Host/IP: {dev.host}") for k, v in dev.state_information.items(): click.echo(f"{k}: {v}") click.echo(click.style("== Generic information ==", bold=True)) click.echo("Time: {}".format(asyncio.run(dev.get_time()))) click.echo("Hardware: {}".format(dev.hw_info["hw_ver"])) click.echo("Software: {}".format(dev.hw_info["sw_ver"])) click.echo(f"MAC (rssi): {dev.mac} ({dev.rssi})") click.echo(f"Location: {dev.location}") ctx.invoke(emeter)
def raw_command(dev: SmartDevice, module, command, parameters): """Run a raw command on the device.""" import ast if parameters is not None: parameters = ast.literal_eval(parameters) res = asyncio.run(dev._query_helper(module, command, parameters)) asyncio.run(dev.update()) click.echo(res)
async def off(dev: SmartDevice, index: int, name: str, transition: int): """Turn the device off.""" await dev.update() if index is not None or name is not None: if not dev.is_strip: click.echo("Index and name are only for power strips!") return dev = cast(SmartStrip, dev) if index is not None: dev = dev.get_plug_by_index(index) elif name: dev = dev.get_plug_by_name(name) click.echo(f"Turning off {dev.alias}") await dev.turn_off(transition=transition)
async def test_diagnostics( hass: HomeAssistant, hass_client: ClientSession, mocked_dev: SmartDevice, fixture_file: str, sysinfo_vars: list[str], ): """Test diagnostics for config entry.""" diagnostics_data = json.loads(load_fixture(fixture_file, "tplink")) mocked_dev._last_update = diagnostics_data["device_last_response"] config_entry = await initialize_config_entry_for_device(hass, mocked_dev) result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) assert isinstance(result, dict) assert "device_last_response" in result # There must be some redactions in place, so the raw data must not match assert result["device_last_response"] != diagnostics_data[ "device_last_response"] last_response = result["device_last_response"] # We should always have sysinfo available assert "system" in last_response assert "get_sysinfo" in last_response["system"] sysinfo = last_response["system"]["get_sysinfo"] for var in sysinfo_vars: assert sysinfo[var] == "**REDACTED**"