Skip to content

Commit

Permalink
add has_entity_name True
Browse files Browse the repository at this point in the history
The friendly_name state attribute is generated by combining then entity name with the device name
  • Loading branch information
dscao authored Jan 15, 2023
1 parent abcb584 commit a066307
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion custom_components/ikuai/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):

class IKUAIButton(ButtonEntity):
"""Define an bjtoon_health_code entity."""

_attr_has_entity_name = True
def __init__(self, hass, kind, coordinator, host, username, passwd, pas):
"""Initialize."""
super().__init__()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ikuai/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def async_step_user(self, user_input={}):
config_data[CONF_USERNAME] = username
config_data[CONF_PASSWD] = passwd
config_data[CONF_PASS] = pas
return self.async_create_entry(title="iKuai", data=config_data)
return self.async_create_entry(title=f"ikuai-{host.split('//')[1]}", data=config_data)

return await self._show_config_form(user_input)

Expand Down
50 changes: 24 additions & 26 deletions custom_components/ikuai/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,112 +24,110 @@
"ikuai_uptime": {
"icon": "mdi:clock-time-eight",
"label": "iKuai启动时长",
"name": "ikuai_uptime",
"name": "Uptime",
},
"ikuai_cpu": {
"icon": "mdi:cpu-64-bit",
"label": "CPU占用",
"name": "ikuai_cpu",
"name": "CPU",
"unit_of_measurement": "%",
},
"ikuai_cputemp": {
"icon": "mdi:thermometer",
"label": "CPU温度",
"name": "ikuai_cputemp",
"name": "CPU_temperature",
"unit_of_measurement": "°C",
"device_class": "temperature",
},
"ikuai_memory": {
"icon": "mdi:memory",
"label": "内存占用",
"name": "ikuai_memory",
"name": "Memory",
"unit_of_measurement": "%",
},
"ikuai_online_user": {
"icon": "mdi:account-multiple",
"label": "在线终端数",
"name": "ikuai_online_user",
"name": "Online_user",
},
"ikuai_ap_online": {
"icon": "mdi:access-point",
"label": "AP数",
"name": "ikuai_ap_online",
"name": "Ap_online",
},
"ikuai_total_up": {
"icon": "mdi:upload-network",
"label": "上传总量",
"name": "ikuai_totalup",
"name": "Totalup",
"unit_of_measurement": "GB",
},
"ikuai_total_down": {
"icon": "mdi:download-network",
"label": "下载总量",
"name": "ikuai_totaldown",
"name": "Totaldown",
"unit_of_measurement": "GB",
},
"ikuai_upload": {
"icon": "mdi:wifi-arrow-up",
"label": "上传速度",
"name": "ikuai_upload",
"name": "Upload",
"unit_of_measurement": "MB/s",
},
"ikuai_download": {
"icon": "mdi:wifi-arrow-down",
"label": "下载速度",
"name": "ikuai_download",
"name": "Download",
"unit_of_measurement": "MB/s",
},
"ikuai_connect_num": {
"icon": "mdi:wifi-arrow-down",
"icon": "mdi:lan-connect",
"label": "连接数",
"name": "ikuai_connect_num",
"name": "Connect_num",
},
"ikuai_wan_ip": {
"icon": "mdi:ip-network-outline",
"label": "WAN IP",
"name": "ikuai_wan_ip",
"name": "Wan_ip",
},
"ikuai_wan_uptime": {
"icon": "mdi:timer-sync-outline",
"label": "WAN Uptime",
"name": "ikuai_wan_uptime",
"name": "Wan_uptime",
},
"ikuai_wan6_ip": {
"icon": "mdi:ip-network",
"label": "WAN IP6",
"name": "ikuai_wan6_ip",
"name": "Wan6_ip",
},
}


BUTTON_TYPES = {
"ikuai_restart": {
"label": "Ikuai重启",
"name": "ikuai_restart",
"name": "Restart",
"device_class": "restart",
"action_body": {"func_name":"reboots","action":"reboots"}
},
"ikuai_restart_reconnect_wan": {
"label": "ikuai重连wan网络",
"name": "ikuai_reconnect_wan",
"label": "重连wan网络",
"name": "Reconnect_wan",
"device_class": "restart",
"action_body": {"func_name":"wan","action":"link_dhcp_reconnect","param":{"id":1}}
},
}

DEVICE_TRACKERS = {
"myiphone1": {
"myiphone": {
"label": "我的手机",
"name": "iphone13_1",
"name": "iPhone13_dscao",
"icon": "mdi:cellphone",
"mac_address": "64:6d:2f:88:4c:e8"
},
"myiphone2": {
"label": "我的手机2",
"name": "iphone13_2",
"hyqiphone": {
"label": "hyq的手机",
"name": "iPhone13_hyq",
"icon": "mdi:cellphone",
"mac_address": "a8:fe:9d:38:82:4d"
},


},
}
2 changes: 2 additions & 0 deletions custom_components/ikuai/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):

class IKUAITracker(ScannerEntity):
"""Define an bjtoon_health_code entity."""

_attr_has_entity_name = True

def __init__(self, hass, kind, coordinator):
"""Initialize."""
Expand Down
1 change: 0 additions & 1 deletion custom_components/ikuai/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"name": "ikuai",
"config_flow": true,
"documentation": "https://github.com/dscao/ikuai",
"issue_tracker": "https://github.com/dscao/ikuai/issues",
"version": "1.2",
"requirements": [],
"dependencies": [],
Expand Down
3 changes: 3 additions & 0 deletions custom_components/ikuai/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):

class IKUAISensor(CoordinatorEntity):
"""Define an bjtoon_health_code entity."""

_attr_has_entity_name = True

def __init__(self, kind, coordinator):
"""Initialize."""
super().__init__(coordinator)
self.kind = kind
self.coordinator = coordinator


@property
def name(self):
Expand Down
7 changes: 4 additions & 3 deletions custom_components/ikuai/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(switchs, False)

class PVESwitch(SwitchEntity):
_attr_has_entity_name = True
def __init__(self, hass, coordinator, host, username, passwd, pas, mac):
"""Initialize."""
super().__init__()
Expand Down Expand Up @@ -76,9 +77,9 @@ def __init__(self, hass, coordinator, host, username, passwd, pas, mac):
if macswitch["id"] == mac:
_LOGGER.debug(macswitch)
if macswitch.get("comment"):
self._name = "ikuai_mac_control_" + str(mac)+"("+macswitch["comment"]+")"
self._name = "Mac_control_" + str(mac)+"("+macswitch["comment"]+")"
else:
self._name = "ikuai_mac_control_" + str(mac)+"(未备注)"
self._name = "Mac_control_" + str(mac)+"(未备注)"
self._mac_address = macswitch["mac"]
self._is_on = macswitch["enabled"] == "yes"
self._state = "on" if self._is_on == True else "off"
Expand All @@ -100,7 +101,7 @@ async def get_access_token(self):
@property
def name(self):
"""Return the name."""
return self._name
return f"{self._name}"

@property
def unique_id(self):
Expand Down

0 comments on commit a066307

Please sign in to comment.