Add entity translations to Fully Kiosk (#95368)

This commit is contained in:
Joost Lekkerkerker 2023-06-27 17:41:41 +02:00 committed by GitHub
parent df65fa3899
commit e7cc839a96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 111 additions and 27 deletions

View file

@ -18,18 +18,18 @@ from .entity import FullyKioskEntity
SENSORS: tuple[BinarySensorEntityDescription, ...] = ( SENSORS: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="kioskMode", key="kioskMode",
name="Kiosk mode", translation_key="kiosk_mode",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="plugged", key="plugged",
name="Plugged in", translation_key="plugged_in",
device_class=BinarySensorDeviceClass.PLUG, device_class=BinarySensorDeviceClass.PLUG,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="isDeviceAdmin", key="isDeviceAdmin",
name="Device admin", translation_key="device_admin",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
) )

View file

@ -39,31 +39,31 @@ class FullyButtonEntityDescription(
BUTTONS: tuple[FullyButtonEntityDescription, ...] = ( BUTTONS: tuple[FullyButtonEntityDescription, ...] = (
FullyButtonEntityDescription( FullyButtonEntityDescription(
key="restartApp", key="restartApp",
name="Restart browser", translation_key="restart_browser",
device_class=ButtonDeviceClass.RESTART, device_class=ButtonDeviceClass.RESTART,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
press_action=lambda fully: fully.restartApp(), press_action=lambda fully: fully.restartApp(),
), ),
FullyButtonEntityDescription( FullyButtonEntityDescription(
key="rebootDevice", key="rebootDevice",
name="Reboot device", translation_key="restart_device",
device_class=ButtonDeviceClass.RESTART, device_class=ButtonDeviceClass.RESTART,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
press_action=lambda fully: fully.rebootDevice(), press_action=lambda fully: fully.rebootDevice(),
), ),
FullyButtonEntityDescription( FullyButtonEntityDescription(
key="toForeground", key="toForeground",
name="Bring to foreground", translation_key="to_foreground",
press_action=lambda fully: fully.toForeground(), press_action=lambda fully: fully.toForeground(),
), ),
FullyButtonEntityDescription( FullyButtonEntityDescription(
key="toBackground", key="toBackground",
name="Send to background", translation_key="to_background",
press_action=lambda fully: fully.toBackground(), press_action=lambda fully: fully.toBackground(),
), ),
FullyButtonEntityDescription( FullyButtonEntityDescription(
key="loadStartUrl", key="loadStartUrl",
name="Load start URL", translation_key="load_start_url",
press_action=lambda fully: fully.loadStartUrl(), press_action=lambda fully: fully.loadStartUrl(),
), ),
) )

View file

@ -33,6 +33,7 @@ async def async_setup_entry(
class FullyMediaPlayer(FullyKioskEntity, MediaPlayerEntity): class FullyMediaPlayer(FullyKioskEntity, MediaPlayerEntity):
"""Representation of a Fully Kiosk Browser media player entity.""" """Representation of a Fully Kiosk Browser media player entity."""
_attr_name = None
_attr_supported_features = MEDIA_SUPPORT_FULLYKIOSK _attr_supported_features = MEDIA_SUPPORT_FULLYKIOSK
_attr_assumed_state = True _attr_assumed_state = True

View file

@ -16,7 +16,7 @@ from .entity import FullyKioskEntity
ENTITY_TYPES: tuple[NumberEntityDescription, ...] = ( ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
NumberEntityDescription( NumberEntityDescription(
key="timeToScreensaverV2", key="timeToScreensaverV2",
name="Screensaver timer", translation_key="screensaver_time",
native_max_value=9999, native_max_value=9999,
native_step=1, native_step=1,
native_min_value=0, native_min_value=0,
@ -25,7 +25,7 @@ ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
), ),
NumberEntityDescription( NumberEntityDescription(
key="screensaverBrightness", key="screensaverBrightness",
name="Screensaver brightness", translation_key="screensaver_brightness",
native_max_value=255, native_max_value=255,
native_step=1, native_step=1,
native_min_value=0, native_min_value=0,
@ -33,7 +33,7 @@ ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
), ),
NumberEntityDescription( NumberEntityDescription(
key="timeToScreenOffV2", key="timeToScreenOffV2",
name="Screen off timer", translation_key="screen_off_time",
native_max_value=9999, native_max_value=9999,
native_step=1, native_step=1,
native_min_value=0, native_min_value=0,
@ -42,7 +42,7 @@ ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
), ),
NumberEntityDescription( NumberEntityDescription(
key="screenBrightness", key="screenBrightness",
name="Screen brightness", translation_key="screen_brightness",
native_max_value=255, native_max_value=255,
native_step=1, native_step=1,
native_min_value=0, native_min_value=0,

View file

@ -51,7 +51,6 @@ class FullySensorEntityDescription(SensorEntityDescription):
SENSORS: tuple[FullySensorEntityDescription, ...] = ( SENSORS: tuple[FullySensorEntityDescription, ...] = (
FullySensorEntityDescription( FullySensorEntityDescription(
key="batteryLevel", key="batteryLevel",
name="Battery",
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -59,23 +58,23 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="currentPage", key="currentPage",
name="Current page", translation_key="current_page",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
state_fn=truncate_url, state_fn=truncate_url,
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="screenOrientation", key="screenOrientation",
name="Screen orientation", translation_key="screen_orientation",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="foregroundApp", key="foregroundApp",
name="Foreground app", translation_key="foreground_app",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="internalStorageFreeSpace", key="internalStorageFreeSpace",
name="Internal storage free space", translation_key="internal_storage_free_space",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
@ -84,7 +83,7 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="internalStorageTotalSpace", key="internalStorageTotalSpace",
name="Internal storage total space", translation_key="internal_storage_total_space",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
@ -93,7 +92,7 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="ramFreeMemory", key="ramFreeMemory",
name="Free memory", translation_key="ram_free_memory",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
@ -102,7 +101,7 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
), ),
FullySensorEntityDescription( FullySensorEntityDescription(
key="ramTotalMemory", key="ramTotalMemory",
name="Total memory", translation_key="ram_total_memory",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,

View file

@ -21,5 +21,89 @@
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]" "already_configured": "[%key:common::config_flow::abort::already_configured_account%]"
} }
},
"entity": {
"binary_sensor": {
"kiosk_mode": {
"name": "Kiosk mode"
},
"plugged_in": {
"name": "Plugged in"
},
"device_admin": {
"name": "Device admin"
}
},
"button": {
"restart_browser": {
"name": "Restart browser"
},
"restart_device": {
"name": "Restart device"
},
"to_foreground": {
"name": "Bring to foreground"
},
"to_background": {
"name": "Send to background"
},
"load_start_url": {
"name": "Load start URL"
}
},
"number": {
"screensaver_time": {
"name": "Screensaver timer"
},
"screensaver_brightness": {
"name": "Screensaver brightness"
},
"screen_off_time": {
"name": "Screen off timer"
},
"screen_brightness": {
"name": "Screen brightness"
}
},
"sensor": {
"current_page": {
"name": "Current page"
},
"screen_orientation": {
"name": "Screen orientation"
},
"foreground_app": {
"name": "Foreground app"
},
"internal_storage_total_space": {
"name": "Internal storage total space"
},
"internal_storage_free_space": {
"name": "Internal storage free space"
},
"ram_free_memory": {
"name": "Free memory"
},
"ram_total_memory": {
"name": "Total memory"
}
},
"switch": {
"screensaver": {
"name": "Screensaver"
},
"maintenance": {
"name": "Maintenance mode"
},
"kiosk": {
"name": "Kiosk lock"
},
"motion_detection": {
"name": "Motion detection"
},
"screen_on": {
"name": "Screen"
}
}
} }
} }

View file

@ -37,14 +37,14 @@ class FullySwitchEntityDescription(
SWITCHES: tuple[FullySwitchEntityDescription, ...] = ( SWITCHES: tuple[FullySwitchEntityDescription, ...] = (
FullySwitchEntityDescription( FullySwitchEntityDescription(
key="screensaver", key="screensaver",
name="Screensaver", translation_key="screensaver",
on_action=lambda fully: fully.startScreensaver(), on_action=lambda fully: fully.startScreensaver(),
off_action=lambda fully: fully.stopScreensaver(), off_action=lambda fully: fully.stopScreensaver(),
is_on_fn=lambda data: data.get("isInScreensaver"), is_on_fn=lambda data: data.get("isInScreensaver"),
), ),
FullySwitchEntityDescription( FullySwitchEntityDescription(
key="maintenance", key="maintenance",
name="Maintenance mode", translation_key="maintenance",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
on_action=lambda fully: fully.enableLockedMode(), on_action=lambda fully: fully.enableLockedMode(),
off_action=lambda fully: fully.disableLockedMode(), off_action=lambda fully: fully.disableLockedMode(),
@ -52,7 +52,7 @@ SWITCHES: tuple[FullySwitchEntityDescription, ...] = (
), ),
FullySwitchEntityDescription( FullySwitchEntityDescription(
key="kiosk", key="kiosk",
name="Kiosk lock", translation_key="kiosk",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
on_action=lambda fully: fully.lockKiosk(), on_action=lambda fully: fully.lockKiosk(),
off_action=lambda fully: fully.unlockKiosk(), off_action=lambda fully: fully.unlockKiosk(),
@ -60,7 +60,7 @@ SWITCHES: tuple[FullySwitchEntityDescription, ...] = (
), ),
FullySwitchEntityDescription( FullySwitchEntityDescription(
key="motion-detection", key="motion-detection",
name="Motion detection", translation_key="motion_detection",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
on_action=lambda fully: fully.enableMotionDetection(), on_action=lambda fully: fully.enableMotionDetection(),
off_action=lambda fully: fully.disableMotionDetection(), off_action=lambda fully: fully.disableMotionDetection(),
@ -68,7 +68,7 @@ SWITCHES: tuple[FullySwitchEntityDescription, ...] = (
), ),
FullySwitchEntityDescription( FullySwitchEntityDescription(
key="screenOn", key="screenOn",
name="Screen", translation_key="screen_on",
on_action=lambda fully: fully.screenOn(), on_action=lambda fully: fully.screenOn(),
off_action=lambda fully: fully.screenOff(), off_action=lambda fully: fully.screenOff(),
is_on_fn=lambda data: data.get("screenOn"), is_on_fn=lambda data: data.get("screenOn"),

View file

@ -30,13 +30,13 @@ async def test_buttons(
) )
assert len(mock_fully_kiosk.restartApp.mock_calls) == 1 assert len(mock_fully_kiosk.restartApp.mock_calls) == 1
entry = entity_registry.async_get("button.amazon_fire_reboot_device") entry = entity_registry.async_get("button.amazon_fire_restart_device")
assert entry assert entry
assert entry.unique_id == "abcdef-123456-rebootDevice" assert entry.unique_id == "abcdef-123456-rebootDevice"
await hass.services.async_call( await hass.services.async_call(
button.DOMAIN, button.DOMAIN,
button.SERVICE_PRESS, button.SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.amazon_fire_reboot_device"}, {ATTR_ENTITY_ID: "button.amazon_fire_restart_device"},
blocking=True, blocking=True,
) )
assert len(mock_fully_kiosk.rebootDevice.mock_calls) == 1 assert len(mock_fully_kiosk.rebootDevice.mock_calls) == 1